【发布时间】:2012-05-02 17:55:50
【问题描述】:
我正在编写一个 JFrame 表单中的可编辑组合框,但我想更改背景颜色。
程序的工作原理: 如果我点击按钮“按下”,那么他的背景组合框需要变成黑色。
我试过了:
1.
cbo.setBackground(Color.BLACK);
但它什么也没做
2
cbo.getEditor().getEditorComponent().setBackground(Color.BLACK);
((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true);
这样做:
代码示例:
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);
}
我正在使用 Java JDK7
有什么建议吗?
【问题讨论】:
-
你能解决你的问题吗?
-
不,问题永远无法解决。如果您有解决方案,请随时分享 :) 问题是针对学校项目的,我从未解决过...
-
相关,可能重复,无法确定:stackoverflow.com/questions/4412902/…
标签: java swing jcombobox java-7 setbackground