在swing中如何设置组件的背景色。在如下代码中,红色闪一下就没了,谁知道应该怎么做吗?谢谢!(分不够了,对不起)import java.awt.*;
import javax.swing.*;
public class Test extends JFrame
{
public Test()
{
this.setSize(400,400);
this.setBackground(Color.red);
} public static void main(String[] args)
{
new Test().setVisible(true);
}
}
import javax.swing.*;
public class Test extends JFrame
{
public Test()
{
this.setSize(400,400);
this.setBackground(Color.red);
} public static void main(String[] args)
{
new Test().setVisible(true);
}
}
解决方案 »
- 请求帮助,查询出错,不知道错在哪?
- 帮我看看这个小代码为什么出错,关于clone
- 对于 java 连接sql server 2005的警告: Failed to load the sqljdbc_auth.dll
- 关于JCreator使用中的一个问题!!!
- [求助]连接https服务器的时候出现下面的异常 是什么原因?
- 关于编译时出现的小错误
- Point 是一个方法吗?为什么我定义为PointTwo就不行呢?
- 如何得到Jdbtable表中某行某列的值并对其进行修改
- 哪个更有前途?散分贴!
- 中间件的采用选择?
- 打印问题:点击一个按扭,打印一个上传的文件(或者是另外一个页面的信息)
- 新下载了JAVA21.6,环境配置出问题,请高手来帮我一下
import javax.swing.*;
public class Test extends JFrame
{
public Test()
{
this.setSize(400,400);
// this.setBackground(Color.red);
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
} public static void main(String[] args)
{
new Test().setVisible(true);
} private void jbInit() throws Exception {
this.getContentPane().setBackground(Color.red);
}
}
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame
{
public Test(){
JLabel jl=new JLabel();
this.setSize(400,400);
this.getContentPane().add(jl);
jl.setBackground(Color.red);
jl.setOpaque(true);
//为什么加上这一句就可以设置为红色,这句什么意思。
} public static void main(String[] args)
{
new Test().setVisible(true);
}
}
container.setBackground(Color.RED);
n.
不透明物
adj.
不透明的, 不传热的, 迟钝的