JCombobox change another JCombobox

for example import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class ComboBoxTwo extends JFrame implements ActionListener, ItemListener { private static final long serialVersionUID = 1L; private JComboBox mainComboBox; private JComboBox subComboBox; private Hashtable<Object, Object> subItems = new Hashtable<Object, Object>(); public ComboBoxTwo() { String[] items = {“Select Item”, “Color”, “Shape”, “Fruit”}; mainComboBox = new JComboBox(items); … Read more

how to add checkbox and combobox in table cell?

Here is combo cell insets replicate demo: import java.awt.*; import java.awt.event.*; import java.util.EventObject; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class ComboCellInsetsDemo { public JComponent makeUI() { String[] columnNames = {“Name”, “Check”, “Condition”}; Object[][] data = { {“bbb”, false, “=”}, {“aaa”, true, “<“} }; DefaultTableModel model = new DefaultTableModel(data, columnNames) { @Override public Class<?> getColumnClass(int … Read more

How to avoid firing actionlistener event of JComboBox when an item is get added into it dynamically in java?

You could remove the action listener before you add the new elements, and add it back once you’re done . Swing is single threaded so there is no need to worry about other threads needing to fire the listener. Your listener could probably also check if something is selected and take appropriate action if not. … Read more

Adding items to a JComboBox

Wrap the values in a class and override the toString() method. class ComboItem { private String key; private String value; public ComboItem(String key, String value) { this.key = key; this.value = value; } @Override public String toString() { return key; } public String getKey() { return key; } public String getValue() { return value; } … Read more

Why is itemStateChanged on JComboBox is called twice when changed?

Have a look at this source: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Tester { public Tester(){ JComboBox box = new JComboBox(); box.addItem(“One”); box.addItem(“Two”); box.addItem(“Three”); box.addItem(“Four”); box.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e){ System.out.println(e.getItem() + ” ” + e.getStateChange() ); } }); JFrame frame = new JFrame(); frame.getContentPane().add(box); frame.pack(); frame.setVisible(true); } public static void main(String … Read more

JComboBox in a JTable cell

One way is to override the getCellEditor() method to return an appropriate editor. Here is an example to get you started: import java.awt.*; import java.awt.event.*; import java.util.List; import java.util.ArrayList; import javax.swing.*; import javax.swing.table.*; public class TableComboBoxByRow extends JFrame { List<TableCellEditor> editors = new ArrayList<TableCellEditor>(3); public TableComboBoxByRow() { // Create the editors to be used for … Read more