如何更改Java面板上的背景颜色? [英] How to change the background color on a Java panel?
本文介绍了如何更改Java面板上的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,我得到的背景是灰色的。我想把它变成黑色。我尝试过像setBackground(color.BLACK)这样的东西;但它没有用。有什么建议?
Right now, the background I get is a grey. I want to change it to black. I tried doing something like setBackground(color.BLACK); but it didnt work. Any suggestions?
public test()
{
setTitle("Adjustment Form");
setSize(670,450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridLayout(4,6,2,2));
setVisible(true);
}
推荐答案
你可以致电:
getContentPane().setBackground(Color.black);
或者将JPanel添加到您使用的JFrame中。然后将您的组件添加到JPanel。这将允许你打电话
Or add a JPanel to the JFrame your using. Then add your components to the JPanel. This will allow you to call
setBackground(Color.black);
在JPanel上设置背景颜色。
on the JPanel to set the background color.
这篇关于如何更改Java面板上的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文