我创建了JComboBox
一个自定义ListCellRenderer
(a 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;
}
我已经单独设置了按钮操作,除了我从组合框中单击按钮时,它没有显示按钮单击视觉效果之外,所有操作都很好。
如何显示 a JButton
inside a的点击视觉效果JComboBox
?