【问题标题】:Show the clicking visual effect of a JButton inside a JComboBox在 JComboBox 中显示 JButton 的点击视觉效果
【发布时间】:2013-01-07 19:09:47
【问题描述】:

我创建了一个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;           
}

我已经单独设置了按钮操作,除了点击时,所有操作都很好 组合框中的按钮不显示按钮单击视觉效果。

如何在JComboBox中显示JButton的点击视觉效果?

【问题讨论】:

  • 1) 我想你会发现这些按钮不充当ActionListener 实例。 2) 为了尽快获得更好的帮助,请发帖SSCCE
  • 另见example

标签: java swing jbutton jcombobox


【解决方案1】:

我想我找到了在 JComboBox 内不显示视觉点击效果的原因 --> Stackoverflow question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    相关资源
    最近更新 更多