Zmień edytowalny kolor tła JComboBox

Programuję edytowalny combobox w formularzu JFrame, ale chcę zmienić kolor tła.

Jak działa program: Jeśli kliknę przycisk „naciśnij”, to kombinacja jego tła musi stać się czarna.

Próbowałem:

1

<code>cbo.setBackground(Color.BLACK);
</code>

Ale nic nie zrobiło

2

<code>cbo.getEditor().getEditorComponent().setBackground(Color.BLACK);

((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true);
</code>

Czy to:

Przykład kodu:

<code>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);
}
</code>

Pracuję z Java JDK7

Jakieś sugestie?

questionAnswers(2)

yourAnswerToTheQuestion