GVKun编程网logo

如何在JavaFX中防止在SPACE键上关闭AutoCompleteCombobox popupmenu(javafx关闭窗口)

14

对于想了解如何在JavaFX中防止在SPACE键上关闭AutoCompleteComboboxpopupmenu的读者,本文将提供新的信息,我们将详细介绍javafx关闭窗口,并且为您提供关于antd

对于想了解如何在JavaFX中防止在SPACE键上关闭AutoCompleteCombobox popupmenu的读者,本文将提供新的信息,我们将详细介绍javafx关闭窗口,并且为您提供关于antd 组件 select 分页懒加载 autocomplete onPopupScroll、AutoComplete Textbox with Additional Parameters From Database、c# – 如何在comboBox.SelectedIndexChanged事件中更改comboBox.Text?、com.intellij.openapi.ui.ComboBoxWithWidePopup的实例源码的有价值信息。

本文目录一览:

如何在JavaFX中防止在SPACE键上关闭AutoCompleteCombobox popupmenu(javafx关闭窗口)

如何在JavaFX中防止在SPACE键上关闭AutoCompleteCombobox popupmenu(javafx关闭窗口)

我借助https://github.com/jesuino/javafx-combox-
autocomplete/blob/master/src/main/java/org/fxapps/ComboBoxAutoComplete.java上提到的代码在JavaFX中创建了AutoCompleteCombobox

但是问题是,当用户按下空格键时,组合框弹出窗口关闭。我想继续使用空格字符进行过滤,并防止弹出窗口关闭。

我已经在组合框上处理了所有三个事件(按键,释放键,键入),但是没有解决方案。我认为这是由组合框项目列表视图上的按键事件引起的。

错误是在提到https://bugs.openjdk.java.net/browse/JDK-8087549
在此处输入链接的描述

我只想知道如何覆盖处理SPACE键按下的事件处理程序。

答案1

小编典典

我也一直试图创建一个AutoCompleteCombobox,并且想知道为什么每次您输入空格时都会关闭弹出窗口,直到我提示您实际的错误在
ComboBoxListViewSkin 类中。

您只需要用一个具有EventFilter的新蒙皮替换ComboBox的蒙皮。

ComboBoxListViewSkin<T> comboBoxListViewSkin = new ComboBoxListViewSkin<T>(comboBox);comboBoxListViewSkin.getPopupContent().addEventFilter(KeyEvent.ANY, (event) -> {    if( event.getCode() == KeyCode.SPACE ) {        event.consume();    }});comboBox.setSkin(comboBoxListViewSkin);

我仅在Ubuntu上使用Oracle Java 10测试了该解决方案,但它也应在其他平台上运行。

antd 组件 select 分页懒加载 autocomplete onPopupScroll

antd 组件 select 分页懒加载 autocomplete onPopupScroll

如果列表数据过大,初始可以加载10-20条数据 ,通过用户搜寻关键字或者滚动select组件分页加载数据解决问题 ,网上资料比较少就写了一下。

 

1. onSearch 可以支持 类似autocomplete功能 异步调用api获取新的列表数据

2.下拉列表滚动  可以实现懒加载 分页加载数据 

 组件代码:

 1  <FormItem {...formItemLayout} label="公司">
 2                 <div id="companyDiv" style={{ position: ''relative'' }}>
 3                   {getFieldDecorator(''checkCompanyIds'', {
 4                     rules: [{ required: true, message: ''请选择公司'' }],
 5                     initialValue:
 6                       planInfo &&
 7                       planInfo.checkCompanyIds &&
 8                       planInfo.checkCompanyIds.split('','').map(Number),
 9                   })(
10                     <Select
11                       placeholder="请输入公司名"
12                       mode="multiple"
13                       labelInValue
14                       notFoundContent={fetching ? <Spin size="small" /> : null}
15                       onSearch={this.fetchCompany}
16                       onChange={this.setCheckNum}
17                       onPopupScroll={this.companyScroll}
18                       filterOption={false}
19                       getPopupContainer={() => document.getElementById(''companyDiv'')}
20                     >
21                       {companyData &&
22                         companyData.map(item => (
23                           <Option value={item.id} key={item.id}>
24                             {item.companyName}
25                           </Option>
26                         ))}
27                     </Select>
28                   )}
29                 </div>
30               </FormItem>

页面滚动加载代码:

 1  companyScroll = e => {
 2     e.persist();
 3     const { target } = e;
 4     if (target.scrollTop + target.offsetHeight === target.scrollHeight) {
 5       const { scrollPage } = this.state;
 6       const nextScrollPage = scrollPage + 1;
 7       this.setState({ scrollPage: nextScrollPage });
 8       this.getCompanyList(nextScrollPage); // 调用api方法
 9     }
10   };

搜索代码:

1   fetchCompany = value => {
2     this.setState({ companyData: [], fetching: true });
3     this.getCompanyList(value); // 关键字模糊查询api
4   };

 

AutoComplete Textbox with Additional Parameters From Database

AutoComplete Textbox with Additional Parameters From Database

为 ajaxToolkit:autocompleteextender 传递3个参数: string prefixText, int count, string contextKey

Introduction

This article explains the concept of the Ajax AutoComplete TextBox to fetch data from the database with additional parameter.

A TextBox can be integrated with the Ajax AutoComplete Extender to perform AutoComplete functionality and it also helps to fetch data from the database. This concept is explained clearly in our prevIoUs article titled “AutoComplete From Database". This article is aimed to provide more kNowledge about the AutoComplete Extender which can take some additional parameters through which we can fine tune a data fetched from the database. To achieve this we need to install the new AjaxControlToolkit version 10618, released on June 2007.
Key Properties
The main properties to achieve this AutoComplete TextBox with additional parameter are contextKey and UseContextKey. These two properties help to set some additional parameters to the prefixText that is passed to the webservice. ContextKey ia a user or page specific context provided to an optional overload of the web method described in the ServiceMethod of the AutoComplete Extender. If the context key is used, it should have the same signature with an additional parameter named contextKey of type string. The UseContextKey is to specify whether or not the contextKey property should be used.

Sample Scenario
We are going to fill a single AutoComplete TextBox with two different types of values based on the condition provided from a DropDownList control. The first type of value will be country name and the second type of value will be the states in US. You can choose the type of values to be filled in the AutoComplete TextBox from the DropDownList provided. This sample is for only demonstration purpose, but in real time you can process any type of contextKey values to achieve excellent stuffs.
Make sure you have installed latest version (10618) of AjaxToolkit control in your development system. In your Ajax Enabled website, drag and drop a TextBox from your ToolBox. Then drag and drop a ScriptManager and autocompleteextender to your Default.aspx page. Then add a webservice to your project as WebService.asmx. Add the ScriptService reference to the webserive as follows.

[System.Web.Script.Services.ScriptService]

Now, write a webmethod ‘GetCountryOrStatesInfo’ to fetch the data from the Country or StatesinUS table as follows

[WebMethod] public string[] GetCountryOrStatesInfo(string prefixText, int count, string contextKey)
{
  int count = 10; 
  string sql; 
  if (contextKey == "Country") 
    sql = "Select Country_Name from Country Where Country_Name like @prefixText"; 
  else 
    sql = "Select States_Name from States Where States_Name like @prefixText"; 
  sqlDataAdapter da = new sqlDataAdapter(sql,”Your connection String”); 
  da.SelectCommand.Parameters.Add("@prefixText",sqlDbType.VarChar, 50).Value = prefixText + "%"; 
  DataTable dt = new DataTable(); 
  da.Fill(dt); 
  string[] items = new string[dt.Rows.Count]; 
  int i = 0; 
  foreach (DaTarow dr in dt.Rows) 
  { 
    items.SetValue(dr[0].ToString(), i); 
    i++; 
   } 
    return items;
}

The above webmethod takes 3 arguments such as prefixText, count and contextKey. So any method that uses contextKey must be with the above signature. The prefixText will pass the initial value entered in the AutoComplete TextBox, count will give the number of items returned to the popup menu of the TextBox and contextKey will be the additional parameter to be passed to the webmethod. So in the above sample webmethod, we pass the type of value to be displayed in the TextBox that is either Country of States.
Next, in the Default.aspx page, set the autocompleteextender’s TargetControlID property to the TextBox Id. Now you can see a new Extenders Tab is added in the TextBox’s Property window. Set ServicePath as WebService.asmx, ServiceMethod as GetCountryOrStatesInfo and useContextKey to true. Specify the default values for contextKey as Country. The code for the AutoComplete Extender will be as follows

<cc1:autocompleteextender ID="autocompleteextender1" runat="server" MinimumPrefixLength="1" ServiceMethod="GetCountryOrStatesInfo" UseContextKey="true" ContextKey="Country" ServicePath="WebService.asmx" TargetControlID="TextBox1"></cc1:autocompleteextender>

Add a DropDownList control to this page, add items as List only Country and List only States. Specify its Autopostback to true. On the OnSelectedindexChanged event of the DropDownList, add the following code

autocompleteextender1.ContextKey = cmbList.SelectedValue;

The code of the DropDownList control will be

<asp:DropDownList ID="cmbList" runat="server" AutopostBack="True" OnSelectedindexChanged="cmbList_SelectedindexChanged"> <asp:ListItem Value="Country">List only Country</asp:ListItem> <asp:ListItem Value="States">List only States</asp:ListItem> </asp:DropDownList>

Save your project and run the application. You can see the AutoComplete TextBox and DropDownList control. Now type some letters in the TextBox, it will populate the corresponding countries. Next change the value in the DropDownList as List Only States, and type some letters in the TextBox it will populate the States from the starting letter you typed.

http://www.aspdotnetcodes.com/AutoComplete_Textbox_Addtional_Parameters.aspx

c# – 如何在comboBox.SelectedIndexChanged事件中更改comboBox.Text?

c# – 如何在comboBox.SelectedIndexChanged事件中更改comboBox.Text?

代码示例:

private void comboBox_SelectedindexChanged(object sender,EventArgs e)
{
    if(some condition)
    {
        comboBox.Text = "new string"
    }
}

我的问题是comboBox文本总是显示所选索引的字符串值而不是新字符串.绕道而行吗?

解决方法

这段代码应该有用……

public Form1()
{
    InitializeComponent();

    comboBox1.Items.AddRange(new String[] { "Item1","Item2","Item3" });
}

private void comboBox1_SelectedindexChanged(object sender,EventArgs e)
{
    String text = "You selected: " + comboBox1.Text;

    BeginInvoke(new Action(() => comboBox1.Text = text));
}

希望能帮助到你… :)

com.intellij.openapi.ui.ComboBoxWithWidePopup的实例源码

com.intellij.openapi.ui.ComboBoxWithWidePopup的实例源码

项目:ApiDebugger    文件:FormDataTableCellEditor.java   
public FormDataTableCellEditor(Project project,JBDebuggerFormTable.ItemInfo itemInfo) {
    component = new JPanel(new BorderLayout());
    editor = new EditorTextField("",project,StdFileTypes.PLAIN_TEXT);
    component.add(editor,BorderLayout.CENTER);
    comboBox = new ComboBoxWithWidePopup<>(ContainerUtil.ar("Text","File"));
    comboBox.setSelectedItem(StringUtil.isEmpty(itemInfo.type) ? "Text" : itemInfo.type);
    comboBox.setFocusable(false);
    comboBox.addItemListener(e -> {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            itemInfo.type = e.getItem().toString();
        }
    });
    component.add(comboBox,BorderLayout.EAST);
}
项目:tools-idea    文件:FramesPanel.java   
public FramesPanel(Project project,DebuggerStateManager stateManager) {
  super(project,stateManager);
  myStateManager = stateManager;

  setLayout(new BorderLayout());

  myThreadsCombo = new ComboBoxWithWidePopup();
  myThreadsCombo.setRenderer(new DebuggerComboBoxRenderer(myThreadsCombo.getRenderer()));
  myThreadsListener = new ThreadsListener();
  myThreadsCombo.addItemListener(myThreadsListener);

  myFramesList = new FramesList(project);
  myFramesListener = new FramesListener();
  myFramesList.addListSelectionListener(myFramesListener);

  myFramesList.addMouseListener(new MouseAdapter() {
    public void mousepressed(final MouseEvent e) {
      int index = myFramesList.locationToIndex(e.getPoint());
      if (index >= 0 && myFramesList.isSelectedindex(index)) {
        processListValue(myFramesList.getModel().getElementAt(index));
      }
    }
  });

  registerThreadsPopupMenu(myFramesList);

  setBorder(null);

  final ActionToolbar toolbar = createtoolbar();
  Wrapper threads = new Wrapper();
  CustomLineBorder border = new CustomLineBorder(CaptionPanel.CNT_ACTIVE_BORDER_COLOR,1,0);
  threads.setBorder(border);
  threads.add(toolbar.getComponent(),BorderLayout.EAST);
  threads.add(myThreadsCombo,BorderLayout.CENTER);
  add(threads,BorderLayout.norTH);
  add(ScrollPaneFactory.createScrollPane(myFramesList),BorderLayout.CENTER);
}
项目:intellij-ce-playground    文件:DestinationFolderComboBox.java   
public DestinationFolderComboBox() {
  super(new ComboBoxWithWidePopup());
}
项目:tools-idea    文件:DestinationFolderComboBox.java   
public DestinationFolderComboBox() {
  super(new ComboBoxWithWidePopup());
}
项目:consulo-java    文件:DestinationFolderComboBox.java   
public DestinationFolderComboBox() {
  super(new ComboBoxWithWidePopup());
}

关于如何在JavaFX中防止在SPACE键上关闭AutoCompleteCombobox popupmenujavafx关闭窗口的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于antd 组件 select 分页懒加载 autocomplete onPopupScroll、AutoComplete Textbox with Additional Parameters From Database、c# – 如何在comboBox.SelectedIndexChanged事件中更改comboBox.Text?、com.intellij.openapi.ui.ComboBoxWithWidePopup的实例源码等相关知识的信息别忘了在本站进行查找喔。

本文标签: