List of usage examples for javax.swing JComboBox setEditable
@BeanProperty(preferred = true, description = "If true, the user can type a new value in the combo box.") public void setEditable(boolean aFlag)
JComboBox
field is editable. From source file:Main.java
public static void main(String[] argv) throws Exception { // Create a read-only combobox String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true); cb.setSelectedItem("item3"); Object obj = cb.getSelectedItem(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Create a read-only combobox String[] items = { "item1", "item2" }; JComboBox readOnlyCB = new JComboBox(items); // Create an editable combobox items = new String[] { "item1", "item2" }; JComboBox editableCB = new JComboBox(items); editableCB.setEditable(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true); MyPopupMenuListener actionListener = new MyPopupMenuListener(); cb.addPopupMenuListener(actionListener); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true); MyItemListener actionListener = new MyItemListener(); cb.addItemListener(actionListener);/*w w w .j a v a 2s. c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.setEditable(true); // Create and register listener MyActionListener actionListener = new MyActionListener(); cb.addActionListener(actionListener); }
From source file:ComboBoxSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; String title = (args.length == 0 ? "Example JComboBox" : args[0]); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentpane = frame.getContentPane(); JComboBox comboBox1 = new JComboBox(labels); comboBox1.setMaximumRowCount(5);/*from w w w.j a va 2s. c o m*/ contentpane.add(comboBox1, BorderLayout.NORTH); JComboBox comboBox2 = new JComboBox(labels); comboBox2.setEditable(true); contentpane.add(comboBox2, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] items = { "A", "B", "C", "D" }; JComboBox<String> combo = new JComboBox<String>(items); combo.setEditable(true); removeButton(combo);//from w w w . ja v a2s.com JOptionPane.showMessageDialog(null, combo); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);// www . j a v a 2 s. c o m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); String elements[] = { "A", "B", "C", "D" }; JComboBox comboBox = new JComboBox(elements); comboBox.setEditable(true); TreeCellEditor comboEditor = new DefaultCellEditor(comboBox); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeEdit.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; JTree tree = new JTree(array); tree.setEditable(true);//from w ww. j a v a2 s . c o m tree.setRootVisible(true); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); String elements[] = { "A", "B", "C", "D" }; JComboBox comboBox = new JComboBox(elements); comboBox.setEditable(true); TreeCellEditor comboEditor = new DefaultCellEditor(comboBox); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String items[] = { "Item1", "item1" }; JFrame f = new JFrame(); JPanel panel = new JPanel(); JComboBox<String> combo = new JComboBox<>(items); combo.setEditable(true); JTextField txt = new JTextField(10); panel.add(combo);//from w w w . ja v a2s .c o m panel.add(txt); f.add(panel); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent ie) { String str = (String) combo.getSelectedItem(); txt.setText(str); } }); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400, 100); f.setVisible(true); }