简体   繁体   English

如何使用另一个JFrame的JComboBox为JFrame设置backgorund颜色?

[英]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? 请问一些想法吗?

PropertiesJPanel背景设置不同的颜色。

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.

相关问题 如何通过 JComboBox 选择打开另一个 JFrame? - How can I open another JFrame through a JComboBox selection? 如何从另一个JFrame引用一个JFrame中的变量? - How can I reference a variable in one JFrame from another JFrame? 如何从一个jframe到另一个jframe访问arraylist - How can I access arraylist from one jframe to another jframe 如何将所选项目数据从 JComboBox 传递到另一个 JFrame class? - How to pass selected item data from JComboBox to another JFrame class? 如何从另一个 JFrame 设置 JFrame 的 JTextField 的文本? - How to set text of a JTextField of a JFrame from another JFrame? 如何通过在另一个jframe中按下按钮将jframe中的文本字段设置为setEditable(true)? - How can I set a textfield in a jframe to setEditable(true) by pressing a button in another jframe? 我如何从另一个jframe函数打开另一个jframe,而不必等待完成函数的执行? - How can i open another jframe from another jframe function without waiting to complete the execution of function? 2秒延迟后如何与另一个JFrame调用JFrame? - How can I call JFrame with another JFrame after 2 Seconds Delay? 如何在一个 jframe 和另一个 jframe 之间传输数据? - How can I transfer data between one jframe to another jframe? 如何使用setForeground使用JFrame,JLabel创建颜色模拟? - How can i Create Color simulation with JFrame, JLabel, using setForeground?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM