Change background color editable JComboBox

see my code example import java.awt.*; import java.util.Vector; import javax.swing.*; import javax.swing.UIManager; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.metal.MetalComboBoxButton; public class MyComboBox { private Vector<String> listSomeString = new Vector<String>(); private JComboBox someComboBox = new JComboBox(listSomeString); private JComboBox editableComboBox = new JComboBox(listSomeString); private JComboBox non_EditableComboBox = new JComboBox(listSomeString); private JFrame frame; public MyComboBox() { listSomeString.add(“-“); listSomeString.add(“Snowboarding”); listSomeString.add(“Rowing”); listSomeString.add(“Knitting”); listSomeString.add(“Speed … Read more

jcombobox filter in java – Look and feel independent

Firstly you are creating new model everytime and then invoking show popup from code which leads to flickering etc. We can modify the model itself. Secondly you set the currently entered text as selected item which seems to have selectAll behavior as noted by others. I have modified the code as follows: public void comboFilter(String … Read more

Putting JComboBox into JTable

Extend JTable with this code: @Override public TableCellEditor getCellEditor(int row, int column) { Object value = super.getValueAt(row, column); if(value != null) { if(value instanceof JComboBox) { return new DefaultCellEditor((JComboBox)value); } return getDefaultEditor(value.getClass()); } return super.getCellEditor(row, column); } This will create a unique JComboBox cell editor for each combo box you get the a value for.

how to add different JComboBox items in a Column of a JTable in Swing

example on java2s.com looks like as works and correctly, then for example (I harcoded JComboBoxes for quick example, and add/change for todays Swing) import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.table.*; public class EachRowEditorExample extends JFrame { private static final long serialVersionUID = 1L; public EachRowEditorExample() { super(“EachRow Editor Example”); try { for … Read more

Dynamically adding items to a JComboBox

How about using ComboBoxModel? Something like this…. JFrame frame = new JFrame(“Combo Box Demo”); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setLayout(new FlowLayout()); Vector comboBoxItems=new Vector(); comboBoxItems.add(“A”); comboBoxItems.add(“B”); comboBoxItems.add(“C”); comboBoxItems.add(“D”); comboBoxItems.add(“E”); final DefaultComboBoxModel model = new DefaultComboBoxModel(comboBoxItems); JComboBox comboBox = new JComboBox(model); frame.add(comboBox); JButton button = new JButton(“Add new element in combo box”); frame.add(button); button.addActionListener(new ActionListener() { @Override public … Read more

Binding comboboxes in swing

I have problems starting my application it loads the list of countries but not the other lists It seems like you have to specifically set the selected index to invoke the listener. jComboBoxCountries.setModel(…) jComboBoxCountries.setSelectedIndex(0); And by selecting a country is charged the list of states but not the list of cities. I would guess this … Read more

Filling combobox from database by using hibernate in Java

I don’t use Hibernate, but given a JPA entity named Customer and a JPA controller named CustomerJpaController, you can do something like this. Update: Code updated to reflect a switch to EclipseLink (JPA 2.1) as the persistence library. import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; import javax.swing.JComboBox; import javax.swing.JFrame; /** * @see http://stackoverflow.com/a/2531942/230513 */ … Read more

How can I change the arrow style in a JComboBox

You can override createArrowButton() in BasicComboBoxUI. BasicArrowButton is a convenient starting point. class ColorArrowUI extends BasicComboBoxUI { public static ComboBoxUI createUI(JComponent c) { return new ColorArrowUI(); } @Override protected JButton createArrowButton() { return new BasicArrowButton( BasicArrowButton.SOUTH, Color.cyan, Color.magenta, Color.yellow, Color.blue); } } Then install it. JComboBox combo = new JComboBox(); combo.setUI(ColorArrowUI.createUI(combo));