【发布时间】:2013-01-07 19:09:47
【问题描述】:
我创建了一个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;
}
我已经单独设置了按钮操作,除了点击时,所有操作都很好 组合框中的按钮不显示按钮单击视觉效果。
如何在JComboBox中显示JButton的点击视觉效果?
【问题讨论】:
标签: java swing jbutton jcombobox