⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autocompletedemopanel.java

📁 java实现浏览器等本地桌面的功能
💻 JAVA
字号:
package org.jdesktop.demo.swingx;import javax.swing.DefaultComboBoxModel;import javax.swing.DefaultListModel;import org.jdesktop.demo.DemoPanel;import org.jdesktop.swingx.autocomplete.*;/** * * @author  Thomas Bierhance */public class AutoCompleteDemoPanel extends DemoPanel {        final static String htmlDescription =            "<html><b>Automatic Completion Demo</b><br/>" +            "Demonstrates the use of the &quot;autocomplete&quot; package " +            "to enable automatic completion for some components: JComboBox " +            "and JTextField/JList<br/>" +            "Note that the strict version only allows items from the list " +            "to be entered while the non-strict version allows any item." +            "</html>";        String[] items = new String[] {        "Alexander", "Artus", "Axel", "Bastian", "Benno", "Bj鰎n",                "Carl Philipp", "Carsten", "Felix", "Fleur", "Florian", "Frederik",                "Jan", "Jonas", "Julian", "Kai", "Karsten", "Markus", "Matthias",                "Moritz", "Nico", "Norman", "Plamen", "Sandra", "Stefan", "Thorsten",                "Tobias", "Werner"    };        public AutoCompleteDemoPanel() {        setName("Automatic Completion Demo");        initComponents();        strictComboBox.setModel(new DefaultComboBoxModel(items));        nonStrictComboBox.setModel(new DefaultComboBoxModel(items));                Configurator.enableAutoCompletion(strictComboBox);        Configurator.enableAutoCompletion(nonStrictComboBox);                DefaultListModel listModel = new DefaultListModel();        for (int i=0,n=items.length;i<n;i++) {            listModel.add(i,items[i]);        }        list.setModel(listModel);        Configurator.enableAutoCompletion(list, textField);        //textField.setText(nonStrictComboBox.getSelectedItem().toString());            }        public String getHtmlDescription() {        return htmlDescription;    }        public String getName() {        return "Autocomplete";    }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents    private void initComponents() {        java.awt.GridBagConstraints gridBagConstraints;        strictComboBoxLabel = new javax.swing.JLabel();        strictComboBox = new javax.swing.JComboBox();        nonStrictComboBoxLabel = new javax.swing.JLabel();        nonStrictComboBox = new javax.swing.JComboBox();        separator = new javax.swing.JSeparator();        textFieldLabel = new javax.swing.JLabel();        textField = new javax.swing.JTextField();        listLabel = new javax.swing.JLabel();        listScrollPane = new javax.swing.JScrollPane();        list = new javax.swing.JList();        setLayout(new java.awt.GridBagLayout());        strictComboBoxLabel.setText("JComboBox (strict)");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(strictComboBoxLabel, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(strictComboBox, gridBagConstraints);        nonStrictComboBoxLabel.setText("JComboBox (non-strict)");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(nonStrictComboBoxLabel, gridBagConstraints);        nonStrictComboBox.setEditable(true);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(nonStrictComboBox, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);        add(separator, gridBagConstraints);        textFieldLabel.setText("JTextField (strict)");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(textFieldLabel, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(textField, gridBagConstraints);        listLabel.setText("JList");        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(listLabel, gridBagConstraints);        listScrollPane.setViewportView(list);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);        add(listScrollPane, gridBagConstraints);    }    // </editor-fold>//GEN-END:initComponents            // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JList list;    private javax.swing.JLabel listLabel;    private javax.swing.JScrollPane listScrollPane;    private javax.swing.JComboBox nonStrictComboBox;    private javax.swing.JLabel nonStrictComboBoxLabel;    private javax.swing.JSeparator separator;    private javax.swing.JComboBox strictComboBox;    private javax.swing.JLabel strictComboBoxLabel;    private javax.swing.JTextField textField;    private javax.swing.JLabel textFieldLabel;    // End of variables declaration//GEN-END:variables    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -