Java 显示JComboBox内JButton的点击视觉效果
我已经创建了一个带有自定义Java 显示JComboBox内JButton的点击视觉效果,java,swing,jbutton,jcombobox,Java,Swing,Jbutton,Jcombobox,我已经创建了一个带有自定义ListCellRenderer(aJButton)的JComboBox,如下所示: 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.setRend
ListCellRenderer
(aJButton
)的JComboBox
,如下所示:
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;
}
我已经分别设置了按钮操作,除了单击外,所有操作都正常
组合框中的按钮不显示按钮单击的视觉效果
如何在
JComboBox
中显示JButton
的点击视觉效果?我想我找到了在JComboBox中不显示视觉点击效果的原因-->1)我想你会发现这些按钮没有充当ActionListener
实例。2) 要更快地获得更好的帮助,请发布一个。另请参见此。