关于java界面的背景上色问题…… setBackground(Color.red)JPanel使用可以改变颜色,而像JFrame、JContentPane使用却改变不了,这是为什么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有时在JFrame里面添加JPanel或其他组件是。就把JFrame给盖住了。。所以这时修改其背景颜色就没用了。。 还是给代码吧import java.awt.*;import javax.swing.*;public class Test { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = (JPanel)frame.getContentPane(); panel.setOpaque(true); panel.setBackground(Color.RED); frame.setSize(100, 100); frame.setVisible(true); }} 不好意思看错了最近老犯晕JFrame包含很多pane从上往下glasspanecontentpanelayeredpanerootpane看下代码import java.awt.*;import javax.swing.*;public class Test { public static void main(String[] args) { JFrame frame = new JFrame(); Component p = frame.getGlassPane(); Container pp = frame.getContentPane(); JLayeredPane ppp = frame.getLayeredPane(); JRootPane pppp = frame.getRootPane(); //((JComponent)pp).setOpaque(false); //1 //pppp.setOpaque(false); //2 p.setBackground(Color.YELLOW); pp.setBackground(Color.BLACK); ppp.setBackground(Color.GREEN); pppp.setBackground(Color.BLUE); frame.setBackground(Color.RED); frame.setSize(100, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }}运行结果显示的是黑色,这是因为glasspane是透明的,contentpane不透明将一句的注释去掉,让contentpane透明,这时候看到的颜色是蓝色因为layeredpane透明,rootpane不透明将2句的注释也去掉,让rootpane透明,并没有得到期望的红色而是白色,好像还有至少一层东西在frame之上至于这个是什么,看了会源码也没找到希望高手解答 那为什么frame可以呢……而JFrame不可以^ jsp\java 判断一个分数能否被除尽 怎么可以将用SWT基本控件写的一些东西导出为SVG图片 (没准你也有此疑惑)对 "equals"的疑问? common-fileupload 实现下载功能 现在一般java做的商用程序,怎么保护源代码不被反编译呢? 求教java处理jpg图像问题(质量问题) 用JAVA写的页面,利用IE打印功能,可以用程序控制页面排版吗? 急,急,急,JTable中不同列的鼠标形状不同,应该如何做? Java 的入门级小师弟,请各位高手指点迷津. java做局域网聊天工具 关于itext的这个问题!我想大家应该也遇到过,但是却很人问!很奇怪
import java.awt.*;
import javax.swing.*;public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = (JPanel)frame.getContentPane();
panel.setOpaque(true);
panel.setBackground(Color.RED);
frame.setSize(100, 100);
frame.setVisible(true);
}
}
最近老犯晕
JFrame包含很多pane
从上往下
glasspane
contentpane
layeredpane
rootpane
看下代码import java.awt.*;
import javax.swing.*;public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
Component p = frame.getGlassPane();
Container pp = frame.getContentPane();
JLayeredPane ppp = frame.getLayeredPane();
JRootPane pppp = frame.getRootPane();
//((JComponent)pp).setOpaque(false); //1
//pppp.setOpaque(false); //2
p.setBackground(Color.YELLOW);
pp.setBackground(Color.BLACK);
ppp.setBackground(Color.GREEN);
pppp.setBackground(Color.BLUE);
frame.setBackground(Color.RED);
frame.setSize(100, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}运行结果显示的是黑色,这是因为glasspane是透明的,contentpane不透明
将一句的注释去掉,让contentpane透明,这时候看到的颜色是蓝色
因为layeredpane透明,rootpane不透明将2句的注释也去掉,让rootpane透明,并没有得到期望的红色
而是白色,好像还有至少一层东西在frame之上
至于这个是什么,看了会源码也没找到
希望高手解答