当前位置: 首页 > 面试题库 >

Java Swing多列自动完成组合框

易星纬
2023-03-14
问题内容

我需要高效的产品项目搜索GUI到销售点应用程序,当前我正在文本字段中使用弹出窗口,并且该弹出窗口包含到表格中,但是效率不高。

在我的弹出窗口中仅显示产品代码,我需要显示其他产品详细信息,例如CODE,类别,名称,价格等。以确定正确的产品。![在此处输入图片描述] [1]

以下图片是我的要求。

/////////////////////////////请查看代码并帮助我进行开发。

以下是我添加的用于回答// DetailedComboBox的代码

    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.Point;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.plaf.basic.BasicComboPopup;

import javax.swing.plaf.basic.ComboPopup;
import javax.swing.plaf.metal.MetalComboBoxUI;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author W.A.R.R.Wijesinghe
 */
public class DetailedComboBox extends JComboBox {

    public static enum Alignment {

        LEFT, RIGHT
    }
    private List<List<? extends Object>> tableData;
    private String[] columnNames;
    private int[] columnWidths;
    private int displayColumn;
    private Alignment popupAlignment = Alignment.LEFT;

    /**
     * Construct a TableComboBox object
     */
    public DetailedComboBox(String[] colNames, int[] colWidths, int displayColumnIndex) {
        super();
        this.columnNames = colNames;
        this.columnWidths = colWidths;
        this.displayColumn = displayColumnIndex;

        setUI(new TableComboBoxUI());
        setEditable(true);
        this.setSelectedIndex(-1);
        JTextField field = (JTextField) this.getEditor().getEditorComponent();
        field.setText("");
        field.addKeyListener(new ComboKeyHandler(this));
    }

    /**
     * Set the type of alignment for the popup table
     */
    public void setPopupAlignment(Alignment alignment) {
        popupAlignment = alignment;
    }

    /**
     * Populate the combobox and drop-down table with the supplied data. If the
     * supplied List is non-null and non-empty, it is assumed that the data is a
     * List of Lists to be used for the drop-down table. The combobox is also
     * populated with the column data from the column defined by
     * <code>displayColumn</code>.
     */
    public void setTableData(List<List<? extends Object>> tableData) {
        this.tableData = (tableData == null
                ? new ArrayList<List<? extends Object>>() : tableData);

        // even though the incoming data is for the table, we must also
        // populate the combobox's data, so first clear the previous list.
        removeAllItems();

        // then load the combobox with data from the appropriate column
        Iterator<List<? extends Object>> iter = this.tableData.iterator();
        while (iter.hasNext()) {
            List<? extends Object> rowData = iter.next();
            addItem(rowData.get(displayColumn));
        }
    }

    public List<? extends Object> getSelectedRow() {
        return tableData.get(getSelectedIndex());
    }

    public List<? extends Object> getRowAt(int row) {
        return tableData.get(row);
    }

    /**
     * The handler for the combobox's components
     */
    private class TableComboBoxUI extends MetalComboBoxUI {

        /**
         * Create a popup component for the ComboBox
         */
        @Override
        protected ComboPopup createPopup() {
            return new TableComboPopup(comboBox, this);
        }

        /**
         * Return the JList component
         */
        public JList getList() {
            return listBox;
        }
    }

    /**
     * The drop-down of the combobox, which is a JTable instead of a JList.
     */
    private class TableComboPopup extends BasicComboPopup implements ListSelectionListener, ItemListener {

        private final JTable table;
        private TableComboBoxUI comboBoxUI;
        private PopupTableModel tableModel;
        private JScrollPane scroll;
//    private JList list = new JList();
//    private ListSelectionListener selectionListener;
//    private ItemListener itemListener;

        /**
         * Construct a popup component that's a table
         */
        public TableComboPopup(JComboBox combo, TableComboBoxUI ui) {
            super(combo);
            this.comboBoxUI = ui;

            tableModel = new PopupTableModel();
            table = new JTable(tableModel);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            table.getTableHeader().setReorderingAllowed(false);

            TableColumnModel tableColumnModel = table.getColumnModel();
            tableColumnModel.setColumnSelectionAllowed(false);

            for (int index = 0; index < table.getColumnCount(); index++) {
                TableColumn tableColumn = tableColumnModel.getColumn(index);
                tableColumn.setPreferredWidth(columnWidths[index]);
            }

            scroll = new JScrollPane(table);
            scroll.setHorizontalScrollBarPolicy(
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

            ListSelectionModel selectionModel = table.getSelectionModel();
            selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            selectionModel.addListSelectionListener(this);
            combo.addItemListener(this);

            table.addMouseListener(new MouseAdapter() {

                @Override
                public void mousePressed(MouseEvent event) {
                    Point p = event.getPoint();
                    int row = table.rowAtPoint(p);

                    comboBox.setSelectedIndex(row);
                    hide();
                }
            });

            table.setBackground(UIManager.getColor("ComboBox.listBackground"));
            table.setForeground(UIManager.getColor("ComboBox.listForeground"));
        }

        /**
         * This method is overridden from BasicComboPopup
         */
        @Override
        public void show() {
            if (isEnabled()) {
                super.removeAll();

                int scrollWidth = table.getPreferredSize().width
                        + ((Integer) UIManager.get("ScrollBar.width")).intValue() + 1;
                int scrollHeight = comboBoxUI.getList().
                        getPreferredScrollableViewportSize().height;
                scroll.setPreferredSize(new Dimension(scrollWidth, scrollHeight));

                super.add(scroll);

                ListSelectionModel selectionModel = table.getSelectionModel();
                selectionModel.removeListSelectionListener(this);
                selectRow();
                selectionModel.addListSelectionListener(this);

                int scrollX = 0;
                int scrollY = comboBox.getBounds().height;

                if (popupAlignment == Alignment.RIGHT) {
                    scrollX = comboBox.getBounds().width - scrollWidth;
                }

                show(comboBox, scrollX, scrollY);
            }
        }

        /**
         * Implemention of ListSelectionListener
         */
        @Override
        public void valueChanged(ListSelectionEvent event) {
            comboBox.setSelectedIndex(table.getSelectedRow());
        }

        /**
         * Implemention of ItemListener
         */
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() != ItemEvent.DESELECTED) {
                ListSelectionModel selectionModel = table.getSelectionModel();
                selectionModel.removeListSelectionListener(this);
                selectRow();
                selectionModel.addListSelectionListener(this);
            }
        }

        /**
         * Sync the selected row of the table with the selected row of the
         * combo.
         */
        private void selectRow() {
            int index = comboBox.getSelectedIndex();

            if (index != -1) {
                table.setRowSelectionInterval(index, index);
                table.scrollRectToVisible(table.getCellRect(index, 0, true));
            }
        }
    }

    /**
     * A model for the popup table's data
     */
    private class PopupTableModel extends AbstractTableModel {

        /**
         * Return the # of columns in the drop-down table
         */
        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        /**
         * Return the # of rows in the drop-down table
         */
        @Override
        public int getRowCount() {
            return tableData == null ? 0 : tableData.size();
        }

        /**
         * Determine the value for a given cell
         */
        @Override
        public Object getValueAt(int row, int col) {
            if (tableData == null || tableData.size() == 0) {
                return "";
            }

            return tableData.get(row).get(col);
        }

        /**
         * All cells in the drop-down table are uneditable
         */
        @Override
        public boolean isCellEditable(int row, int col) {
            return false;
        }

        /**
         * Pull the column names out of the tableInfo object for the header
         */
        @Override
        public String getColumnName(int column) {
            String columnName = null;

            if (column >= 0 && column < columnNames.length) {
                columnName = columnNames[column].toString();
            }

            return (columnName == null) ? super.getColumnName(column) : columnName;
        }
    }
}

class ComboKeyHandler extends KeyAdapter {

    private final DetailedComboBox comboBox;
    //  private final Vector<String> list = new Vector<String>();
    private final List<List<?>> list = new ArrayList<>();

    public ComboKeyHandler(DetailedComboBox combo) {
        this.comboBox = combo;
        for (int i = 0; i < comboBox.getModel().getSize(); i++) {


            List<? extends Object> rowData = combo.getRowAt(i);
            // name.setText(rowData.get(1).toString());
            //  capital.setText(rowData.get(2).toString());
            list.add(rowData);
            // list.addElement((String) comboBox.getItemAt(i));
        }
    }
    private boolean shouldHide = false;

    @Override
    public void keyTyped(final KeyEvent e) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                String text = ((JTextField) e.getSource()).getText();
                System.out.println(text);
                if (text.length() == 0) {
                    setSuggestionModel(comboBox, list, "");
                    comboBox.hidePopup();
                } else {
                    List<List<?>> m = getSuggestedModel(list, text);
                    if (m.isEmpty() || shouldHide) {
                        comboBox.hidePopup();
                    } else {
                        setSuggestionModel(comboBox, m, text);
                        comboBox.showPopup();
                    }
                }
            }
        });
    }

    @Override
    public void keyPressed(KeyEvent e) {
        JTextField textField = (JTextField) e.getSource();
        String text = textField.getText();
        shouldHide = false;
        switch (e.getKeyCode()) {
            case KeyEvent.VK_RIGHT:


                for (Iterator<List<?>> it = list.iterator(); it.hasNext();) {
                    if (!it.next().contains("How")) {
                        it.remove(); // NOTE: Iterator's remove method, not ArrayList's, is used.
                    }
                    return;
                }

                /*
                 * for (String s : list { if (s.startsWith(text)) {
                 * textField.setText(s); return; } }
                 *
                 */

                break;
            case KeyEvent.VK_ENTER:
                if (!list.contains(text)) {
                    list.add(new ArrayList<>(Arrays.asList(text, "a", "a")));

                    //setSuggestionModel(comboBox, new DefaultComboBoxModel(list), text);
                    setSuggestionModel(comboBox, getSuggestedModel(list, text), text);
                }
                shouldHide = false;
                break;
            case KeyEvent.VK_ESCAPE:
                shouldHide = true;
                break;
            default:
                break;
        }
    }

    private static void setSuggestionModel(DetailedComboBox comboBox, List<List<?>> newList, String str) {
        comboBox.setTableData(newList);
        comboBox.setSelectedIndex(-1);
        ((JTextField) comboBox.getEditor().getEditorComponent()).setText(str);
    }

    private static List<List<?>> getSuggestedModel(List<List<?>> list, String text) {
        List<List<?>> m = new ArrayList<>();


        for (Iterator<List<?>> it = list.iterator(); it.hasNext();) {
            if (!it.next().contains(text)) {
                it.remove(); // NOTE: Iterator's remove method, not ArrayList's, is used.
            }
            m = (List<List<?>>) it;
        }
        return m;

        /*
         * for (String s : list) { if (s.startsWith(text)) { m.addElement(s); }
         * } return m;
         *
         */
    }
}

// DetailedComboBoxDemo

    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.*;

/**
 *
 * @author W.A.R.R.Wijesinghe
 */
public class DetailedComboBoxDemo implements Runnable {

    private DetailedComboBox combo;
    private JTextField name;
    private JTextField capital;

    @Override
    public void run() {
        List<List<?>> tableData = new ArrayList<>();
        tableData.add(new ArrayList<>(  Arrays.asList("MD", "Maryland", "Annapolis")));

        tableData.add(new ArrayList<>(
                Arrays.asList("NH", "New Hampshire", "Concord")));
        tableData.add(new ArrayList<>(
                Arrays.asList("NJ", "New Jersey", "Trenton")));
        tableData.add(new ArrayList<>(
                Arrays.asList("NM", "New Mexico", "Santa Fe")));
        tableData.add(new ArrayList<>(
                Arrays.asList("ND", "North Dakota", "Bismark")));

        String[] columns = new String[]{"State", "Name", "Capital"};
        int[] widths = new int[]{50, 100, 100};

        combo = new DetailedComboBox(columns, widths, 0);
        combo.setTableData(tableData);
        combo.setSelectedIndex(-1);
        combo.setPopupAlignment(DetailedComboBox.Alignment.LEFT);
                combo.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                showDetails();
            }
        });

        name = new JTextField(10);
        capital = new JTextField(10);
        name.setEditable(false);
        capital.setEditable(false);

        JPanel p = new JPanel(new FlowLayout());
        p.add(new JLabel("State"));
        p.add(combo);
        p.add(new JLabel("Name"));
        p.add(name);
        p.add(new JLabel("Capital"));
        p.add(capital);

        JFrame frame = new JFrame("DetailedComboBox Demo");

        frame.getContentPane().add(p, BorderLayout.CENTER);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    private void showDetails() {
        List<? extends Object> rowData = combo.getSelectedRow();
        name.setText(rowData.get(1).toString());
        capital.setText(rowData.get(2).toString());
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new DetailedComboBoxDemo());
    }
}

问题答案:

这是一个JComboBox,它使用JTable而不是JList进行下拉。您需要为其提供表数据(列表列表),而不是通常的表数据。抱歉,没有自动完成功能。

我已经使用了多年了。它有效,但我没有承诺。哎呀,实验甚至还剩下一些死代码。多年来,我只是从不同的代码示例中汲取了不同的想法,这简直就是一团糟。我敢肯定还有改进的余地。

详细的组合框:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.*;
import javax.swing.plaf.metal.*;
import javax.swing.table.*;

/**
 * A JComboBox that has a JTable as a drop-down instead of a JList
 */
public class DetailedComboBox extends JComboBox
{
  public static enum Alignment {LEFT, RIGHT}

  private List<List<? extends Object>> tableData;
  private String[] columnNames;
  private int[] columnWidths;
  private int displayColumn;
  private Alignment popupAlignment = Alignment.LEFT;

  /**
   * Construct a TableComboBox object
   */
  public DetailedComboBox(String[] colNames, int[] colWidths,
                          int displayColumnIndex)
  {
    super();
    this.columnNames = colNames;
    this.columnWidths = colWidths;
    this.displayColumn = displayColumnIndex;

    setUI(new TableComboBoxUI());
    setEditable(false);
  }

  /**
   * Set the type of alignment for the popup table
   */
  public void setPopupAlignment(Alignment alignment)
  {
    popupAlignment = alignment;
  }

  /**
   * Populate the combobox and drop-down table with the supplied data.
   * If the supplied List is non-null and non-empty, it is assumed that
   * the data is a List of Lists to be used for the drop-down table.
   * The combobox is also populated with the column data from the
   * column defined by <code>displayColumn</code>.
   */
  public void setTableData(List<List<? extends Object>> tableData)
  {
    this.tableData = (tableData == null ?
        new ArrayList<List<? extends Object>>() : tableData);

    // even though the incoming data is for the table, we must also
    // populate the combobox's data, so first clear the previous list.
    removeAllItems();

    // then load the combobox with data from the appropriate column
    Iterator<List<? extends Object>> iter = this.tableData.iterator();
    while (iter.hasNext())
    {
      List<? extends Object> rowData = iter.next();
      addItem(rowData.get(displayColumn));
    }
  }

  public List<? extends Object> getSelectedRow()
  {
    return tableData.get(getSelectedIndex());
  }

  /**
   * The handler for the combobox's components
   */
  private class TableComboBoxUI extends MetalComboBoxUI
  {
    /**
     * Create a popup component for the ComboBox
     */
    @Override
    protected ComboPopup createPopup()
    {
      return new TableComboPopup(comboBox, this);
    }

    /**
     * Return the JList component
     */
    public JList getList()
    {
      return listBox;
    }
  }

  /**
   * The drop-down of the combobox, which is a JTable instead of a JList.
   */
  private class TableComboPopup extends BasicComboPopup
      implements ListSelectionListener, ItemListener
  {
    private final JTable table;

    private TableComboBoxUI comboBoxUI;
    private PopupTableModel tableModel;
    private JScrollPane scroll;
//    private JList list = new JList();
//    private ListSelectionListener selectionListener;
//    private ItemListener itemListener;

    /**
     * Construct a popup component that's a table
     */
    public TableComboPopup(JComboBox combo, TableComboBoxUI ui)
    {
      super(combo);
      this.comboBoxUI = ui;

      tableModel = new PopupTableModel();
      table = new JTable(tableModel);
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      table.getTableHeader().setReorderingAllowed(false);

      TableColumnModel tableColumnModel = table.getColumnModel();
      tableColumnModel.setColumnSelectionAllowed(false);

      for (int index = 0; index < table.getColumnCount(); index++)
      {
        TableColumn tableColumn = tableColumnModel.getColumn(index);
        tableColumn.setPreferredWidth(columnWidths[index]);
      }

      scroll = new JScrollPane(table);
      scroll.setHorizontalScrollBarPolicy(
          JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

      ListSelectionModel selectionModel = table.getSelectionModel();
      selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      selectionModel.addListSelectionListener(this);
      combo.addItemListener(this);

      table.addMouseListener(new MouseAdapter()
      {
        @Override
        public void mousePressed(MouseEvent event)
        {
          Point p = event.getPoint();
          int row = table.rowAtPoint(p);

          comboBox.setSelectedIndex(row);
          hide();
        }
      });

      table.setBackground(UIManager.getColor("ComboBox.listBackground"));
      table.setForeground(UIManager.getColor("ComboBox.listForeground"));
    }

    /**
     * This method is overridden from BasicComboPopup
     */
    @Override
    public void show()
    {
      if (isEnabled())
      {
        super.removeAll();

        int scrollWidth = table.getPreferredSize().width +
            ((Integer) UIManager.get("ScrollBar.width")).intValue() + 1;
        int scrollHeight = comboBoxUI.getList().
                           getPreferredScrollableViewportSize().height;
        scroll.setPreferredSize(new Dimension(scrollWidth, scrollHeight));

        super.add(scroll);

        ListSelectionModel selectionModel = table.getSelectionModel();
        selectionModel.removeListSelectionListener(this);
        selectRow();
        selectionModel.addListSelectionListener(this);

        int scrollX = 0;
        int scrollY = comboBox.getBounds().height;

        if (popupAlignment == Alignment.RIGHT)
        {
          scrollX = comboBox.getBounds().width - scrollWidth;
        }

        show(comboBox, scrollX, scrollY);
      }
    }

    /**
     * Implemention of ListSelectionListener
     */
    public void valueChanged(ListSelectionEvent event)
    {
      comboBox.setSelectedIndex(table.getSelectedRow());
    }

    /**
     * Implemention of ItemListener
     */
    public void itemStateChanged(ItemEvent event)
    {
      if (event.getStateChange() != ItemEvent.DESELECTED)
      {
        ListSelectionModel selectionModel = table.getSelectionModel();
        selectionModel.removeListSelectionListener(this);
        selectRow();
        selectionModel.addListSelectionListener(this);
      }
    }

    /**
     * Sync the selected row of the table with the selected row of the combo.
     */
    private void selectRow()
    {
      int index = comboBox.getSelectedIndex();

      if (index != -1)
      {
        table.setRowSelectionInterval(index, index);
        table.scrollRectToVisible(table.getCellRect(index, 0, true));
      }
    }
  }

  /**
   * A model for the popup table's data
   */
  private class PopupTableModel extends AbstractTableModel
  {
    /**
     * Return the # of columns in the drop-down table
     */
    public int getColumnCount()
    {
      return columnNames.length;
    }

    /**
     * Return the # of rows in the drop-down table
     */
    public int getRowCount()
    {
      return tableData == null ? 0 : tableData.size();
    }

    /**
     * Determine the value for a given cell
     */
    public Object getValueAt(int row, int col)
    {
      if (tableData == null || tableData.size() == 0)
      {
        return "";
      }

      return tableData.get(row).get(col);
    }

    /**
     * All cells in the drop-down table are uneditable
     */
    @Override
    public boolean isCellEditable(int row, int col)
    {
      return false;
    }

    /**
     * Pull the column names out of the tableInfo object for the header
     */
    @Override
    public String getColumnName(int column)
    {
      String columnName = null;

      if (column >= 0 && column < columnNames.length)
      {
        columnName = columnNames[column].toString();
      }

      return (columnName == null) ? super.getColumnName(column) : columnName;
    }
  }
}

司机:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;

import javax.swing.*;

public class DetailedComboBoxDemo implements Runnable
{
  private DetailedComboBox combo;
  private JTextField name;
  private JTextField capital;

  public void run()
  {
    List<List<?>> tableData = new ArrayList<List<?>>();
    tableData.add(new ArrayList<String>(
                  Arrays.asList("MD", "Maryland", "Annapolis")));
    tableData.add(new ArrayList<String>(
                  Arrays.asList("NH", "New Hampshire", "Concord")));
    tableData.add(new ArrayList<String>(
                  Arrays.asList("NJ", "New Jersey", "Trenton")));
    tableData.add(new ArrayList<String>(
                  Arrays.asList("NM", "New Mexico", "Santa Fe")));
    tableData.add(new ArrayList<String>(
                  Arrays.asList("ND", "North Dakota", "Bismark")));

    String[] columns = new String[]{"State", "Name", "Capital"};
    int[] widths = new int[]{50, 100, 100};

    combo = new DetailedComboBox(columns, widths, 0);
    combo.setTableData(tableData);
    combo.setSelectedIndex(-1);
    combo.setPopupAlignment(DetailedComboBox.Alignment.LEFT);
    combo.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        showDetails();
      }
    });

    name = new JTextField(10);
    capital = new JTextField(10);
    name.setEditable(false);
    capital.setEditable(false);

    JPanel p = new JPanel(new FlowLayout());
    p.add(new JLabel("State"));
    p.add(combo);
    p.add(new JLabel("Name"));
    p.add(name);
    p.add(new JLabel("Capital"));    
    p.add(capital);

    JFrame frame = new JFrame("DetailedComboBox Demo");
    frame.getContentPane().add(p, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }

  private void showDetails()
  {
    List<? extends Object> rowData = combo.getSelectedRow();
    name.setText(rowData.get(1).toString());
    capital.setText(rowData.get(2).toString());
  }

  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(new DetailedComboBoxDemo());
  }
}


 类似资料:
  • 问题内容: 我正在寻找一种将自动完成功能添加到JavaFX的方法ComboBox。经过大量搜索之后,该在这里提问了。 这AutoFillBox是已知的,但不是我要搜索的内容。我想要的是一个可编辑的组合框,在键入列表时应进行过滤。但是我也想打开列表而不输入并查看整个项目。 任何想法? 问题答案: 我找到了一个对我有用的解决方案: 你可以用 基于此,我根据自己的需要对其进行了自定义。 随时使用它,如果

  • 我正在寻找一种将自动完成添加到JavaFX的方法。 这个是已知的,但不是我正在搜索的。我想要的是一个可编辑的组合框,在输入时,列表应该被过滤掉。但我也想打开列表,而不必输入和查看所有项目。 知道吗?

  • 问题内容: 有谁知道用Knockout JS模板创建自动完成组合框的最佳方法吗? 我有以下模板: 有时候,这个清单很长,我想让Knockout在jQuery自动完成功能或一些直接的JavaScript代码方面表现出色,但收效甚微。 另外,jQuery.Autocomplete需要输入字段。有任何想法吗? 问题答案: 这是我编写的jQuery UI自动完成绑定。它的目的是镜像,,,与几个新增的选择要

  • 我正在使用primefaces AutoMLETE强制选择按名称搜索帐户 JSF组件 Bean方法: 这工作正常,现在如果我想把搜索更改为在查询值中搜索账号。我使用了以下内容: 但是,过滤器只返回搜索号码,而忽略名称搜索。我怎样才能做到这一点?

  • 问题内容: 如何使用Redis实现自动完成功能? 比如说我有一个数组。当我型我得到 我希望你明白这一点。我如何有效地使用redis命令来实现这一点(如果可能,但我认为是)。如果我能通过telnet尝试一些简单的命令来模仿这种行为,那就太好了。 谢谢 问题答案: 如果您要处理的是大型数据集,建议您考虑将其实现。我将一小部分Ruby做到了这一点: 例如: 在Wikipedia的Tries条目上阅读有关

  • 自动完成是现代网站中经常使用的一种机制,用于向用户提供他/她在文本框中键入的单词开头的建议列表。 然后,用户可以从列表中选择一个项目,该项目将显示在输入字段中。 此功能可防止用户输入整个单词或一组单词。 JQueryUI提供了一个自动完成窗口小部件 - 一个与下拉列表非常相似的控件,但过滤选项只显示与用户在控件中键入的内容相匹配的选项。 jQueryUI提供了autocomplete()方法,用于