相关疑难解决方法(0)

更改背景颜色可编辑JComboBox

我正在编写JFrame表单中的可编辑组合框,但我想改变背景颜色.

程序如何工作:如果我点击"按"按钮,那么组合框的背景需要变成黑色.

我试过了:

1.

cbo.setBackground(Color.BLACK);
Run Code Online (Sandbox Code Playgroud)

但它没有做任何事情

2

cbo.getEditor().getEditorComponent().setBackground(Color.BLACK);

((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true);
Run Code Online (Sandbox Code Playgroud)

做这个:

图片

代码示例:

public class NewJFrame extends javax.swing.JFrame {

    private JComboBox cboCategorie;

    public NewJFrame() {
        initComponents();

        cboCategorie = new JComboBox();
        cboCategorie.setBounds(10, 10, 250, 26);
        cboCategorie.setVisible(true);
        cboCategorie.setEditable(true);
        this.add(cboCategorie);

    }

private void pressActionPerformed(java.awt.event.ActionEvent evt) {
        cboCategorie.getEditor().getEditorComponent().setBackground(Color.BLACK);
        ((JTextField) cboCategorie.getEditor().getEditorComponent()).setOpaque(true);
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Java JDK7

任何sugestions?

java swing jcombobox java-7 setbackground

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

java-7 ×1

jcombobox ×1

setbackground ×1

swing ×1