I have created a JComboBox
with a custom ListCellRenderer
(a JButton
) as below:
JButton b1 = new JButton("One");
JButton b2 = new JButton("Two");
JButton b3 = new JButton("Three");
JButton[] buttonList = {b1, b2, b3};
JComboBox box = new JComboBox(buttonList);
box.setRenderer(new CellRenderer());
//...
/**************** Custom Cell Renderer Class ****************/
class CellRenderer implements ListCellRenderer {
public Component getListCellRendererComponent(JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
JButton button = (JButton) value;
return button;
}
I have set button actions separately and all are works fine except when I am clicking a button from the combo box it doesn't shows the button clicking visual effect.
How to show the clicking visual effect of a JButton
inside a JComboBox
?