[英]How can I set the backgorund color for a JFrame using a JComboBox from another JFrame?
Actually, I'm trying to do a "Setting" window for a game and I want to set the background color of another window. 实际上,我正在尝试为游戏创建“设置”窗口,并且我想设置另一个窗口的背景色。 I have no idea what to do.
我不知道该怎么做。 Some ideas pls?
请问一些想法吗?
从Properties
为JPanel
背景设置不同的颜色。
You can implement it in different places. 您可以在不同的地方实现它。 One of the ways is constructor, for example:
一种方法是构造函数,例如:
public YourClassPanel() {
// to set Look&Feel
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException ex) {
Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(ControlPanel.class.getName()).log(Level.SEVERE, null, ex);
}
SwingUtilities.updateComponentTreeUI(this);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
ControlPanel.tgp = null;
}
});
this.setBounds(0, 0, 710, 580);
this.setTitle("Buffer Allocation Panel");
this.setPreferredSize(null);
this.setResizable(false);
this.setBackground(Color.yellow); //to set Background
this.setForeground(Color.magenta); // to set Foreground
this.setOpaque(a!=255); // to set Opaque
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.