0

我创建了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 JButtoninside a的点击视觉效果JComboBox

4

1 回答 1

0

我想我找到了没有在 JComboBox 内显示视觉点击效果的原因来自这个 --> Stackoverflow 问题

于 2013-01-24T05:29:02.070 回答