我创建了一个JComboBox
,其中包含自定义ListCellRenderer
(JButton
),如下所示:
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;
}
我已单独设置按钮操作,除非我点击,否则一切正常 组合框中的按钮不显示单击视觉效果的按钮。
如何在JButton
内显示JComboBox
的点击视觉效果?