代码之家  ›  专栏  ›  技术社区  ›  Yair Altman

我可以修改现有对象的jcombobox弹出式背景色吗?

  •  5
  • Yair Altman  · 技术社区  · 15 年前

    我有一个现有的jcombobox对象。我可以使用内部方法修改它的许多属性。但是,我找不到类似的方法来定制弹出窗口的外观——特别是弹出窗口的背景色。我有一个现有的对象,所以我希望使用它现有的方法/属性,而不是编写一个专用的类。这有可能吗?

    注意:这个问题是 不是 与上面链接的问题相同(错误地声明此问题已经有答案):该问题询问了 选定项目 的bgcolor(在ComboBox的编辑框中);我正在询问 弹出框 的颜色。

    3 回复  |  直到 9 年前
        1
  •  3
  •   BoffinBrain    15 年前

    ListCellRenderer DefaultListCellRenderer JLabel setBackground()

    JComboBox combo = new JComboBox(new String[] { "A", "B", "C", "D" });
    combo.setRenderer(new DefaultListCellRenderer() {
        public void paint(Graphics g) {
            setBackground(Color.YELLOW);
            setForeground(Color.RED);
            super.paint(g);
        }
    });
        3
  •  0
  •   dogbane    15 年前

    comboBox.setBackground(color);