Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 显示JComboBox内JButton的点击视觉效果_Java_Swing_Jbutton_Jcombobox - Fatal编程技术网

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
(a
JButton
)的
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) 要更快地获得更好的帮助,请发布一个。另请参见此。