0

如何更改基本 ComboBox UI 的配色方案?我尝试过的是:setForeGround、setBackground、setOpaque(true)、setOpaque(false) setBorder。但这些都不起作用。

我现在的代码是:

    weaponCB.setBounds(27,250,150,30);
    weaponCB.setUI(new BasicComboBoxUI());
    weaponCB.setForeground(Color.white);
    weaponCB.setBackground(Color.black);
    weaponCB.setBorder(whiteBorder);
    weaponCB.setFont(new Font("Trajan Pro", Font.BOLD, 15));
    lP.add(weaponCB, new Integer(2));

这是出现的:

在此处输入图像描述

但我真正想要的是下拉部分(白色区域)看起来像显示器,(黑色区域带有白色的“LANCE”)即背景为黑色,边框为白色,文字为白色。如果这是可能的,你告诉我怎么做,这对我会有很大的帮助。谢谢。

4

1 回答 1

0

很奇怪,但是当我把武器CB.setUI(new BasicComboBoxUI()); 在 setBackground 和 setForeground 和 setBorder 下,组合框按预期工作。只有边框不显示。

    weaponCB.setBounds(27,250,150,30);
    weaponCB.setForeground(Color.white);
    weaponCB.setBackground(Color.black);
    weaponCB.setBorder(whiteBorder);
    weaponCB.setFont(new Font("Trajan Pro", Font.BOLD, 15));
    lP.add(weaponCB, new Integer(2));
    weaponCB.setUI(new BasicComboBoxUI());

在此处输入图像描述

另一件有效的事情是:

@Override
            public void paint(Graphics g) {
                setBackground(Color.black);
                setForeground(Color.white);
                super.paint(g);
            }
        });
于 2012-02-14T10:25:14.087 回答