List of usage examples for javax.swing JComboBox addItem
public void addItem(E item)
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = { "item1", "item2" }; JComboBox cb = new JComboBox(items); cb.addItem("item3"); }
From source file:AddingItemToComboBox.java
License:asdf
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox jComboBox1 = new JComboBox(); jComboBox1.addItem("asdf"); Object cmboitem = jComboBox1.getSelectedItem(); System.out.println(cmboitem); frame.add(jComboBox1);//from w ww . j a v a 2 s . c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox<String> box = new JComboBox<>(); box.addItem("One"); box.addItem("Two"); box.addItem("Three"); box.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { System.out.println(e.getItem()); }/*from ww w. j a va 2 s . c om*/ } }); JFrame frame = new JFrame(); frame.getContentPane().add(box); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setSize(450, 250);//from w ww .j av a 2 s .c o m JTable table = new JTable(5, 5); TableColumn testColumn = table.getColumnModel().getColumn(0); JComboBox<String> comboBox = new JComboBox<>(); comboBox.addItem("This"); comboBox.addItem("is"); comboBox.addItem("a"); comboBox.addItem("Sample program"); testColumn.setCellEditor(new DefaultCellEditor(comboBox)); frame.add(table); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JPanel p = new JPanel(); p.setLayout(new GridLayout(2, 1)); JList<String> lista = new JList<>(new String[] { "1", "2", "3", "4" }); p.add(new JScrollPane(lista)); JComboBox<String> combo = new JComboBox<>(); for (int i = 0; i < 100; i++) { combo.addItem(Integer.toString(i)); p.add(combo);// w w w . j av a2 s .c o m } JFrame f = new JFrame(); f.getContentPane().add(p, BorderLayout.CENTER); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(200, 200); f.setVisible(true); }
From source file:DateComboBoxRenderer.java
public static void main(String[] str) { JComboBox combo = new JComboBox(); GregorianCalendar calendar = new GregorianCalendar(); combo.addItem(calendar.getTime()); calendar.roll(GregorianCalendar.DAY_OF_MONTH, 1); combo.addItem(calendar.getTime());/*from www .j a v a2 s. com*/ combo.setRenderer(new DateComboBoxRenderer()); JFrame frame = new JFrame(); JPanel panel = new JPanel(); panel.add(new JLabel("Date Combo: ")); panel.add(combo); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox combo = new JComboBox(); combo.setEditable(true);// ww w. ja v a 2s . com for (int i = 0; i < 10; i++) { combo.addItem(i); } JLabel tip = new JLabel(); tip.setText("Outside combobox"); JPanel panel = new JPanel(); panel.add(combo); panel.add(tip); panel.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { tip.setText("Outside combobox"); } @Override public void mouseExited(MouseEvent e) { Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); tip.setText(c != null && SwingUtilities.isDescendingFrom(c, combo) ? "Inside combo box" : "Outside combobox"); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox<String> emptyBox = new JComboBox<String>(); emptyBox.addActionListener(new ActionListener() { @Override/*ww w. j a va2 s . co m*/ public void actionPerformed(ActionEvent e) { Thread.dumpStack(); } }); emptyBox.addItem("test"); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox<String> comboBox = new JComboBox<>(new String[] { "Something", "Stuff", "Beep" }); JButton add = new JButton("Add item"); add.addActionListener(new ActionListener() { @Override// w ww .jav a 2 s . c o m public void actionPerformed(ActionEvent e) { comboBox.addItem("Item"); } }); frame.add(comboBox); frame.add(add, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:ColorComboRenderer.java
public static void main(String[] a) { JComboBox cbColor = new JComboBox(); int[] values = new int[] { 0, 128, 192, 255 }; for (int r = 0; r < values.length; r++) for (int g = 0; g < values.length; g++) for (int b = 0; b < values.length; b++) { Color c = new Color(values[r], values[g], values[b]); cbColor.addItem(c); }/*from w w w .j a v a 2 s. co m*/ cbColor.setRenderer(new ColorComboRenderer()); JFrame f = new JFrame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.getContentPane().add(cbColor); f.pack(); f.setSize(new Dimension(300, 80)); f.show(); }