在JComboBox中显示JButton的单击视觉效果

时间:2013-01-24 05:09:10

标签: java swing jbutton jcombobox

我创建了一个JComboBox,其中包含自定义ListCellRendererJButton),如下所示:

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的点击视觉效果?

1 个答案:

答案 0 :(得分:0)

我想我发现没有在JComboBox中显示视觉点击效果的原因由此 - > Stackoverflow question