AutoCompleteDemoPanel.java
资源名称:swingx.zip [点击查看]
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:7k
源码类别:
xml/soap/webservice
开发平台:
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 "autocomplete" 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
- }