我正在编写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?