setBackground 是未修饰的 JFrame
setBackground is undecorated JFrame
好的..我正在重写这个问题..
我发现 setUndecorated()
不是问题所在。
问题是setBackground(new Color(0, 0, 0, 0)
经过一些尝试,CardLayout
显示了正确的结果
当背景的 Alpha 通道为 1(完全不透明)时。
否则显示错误结果。
public SmartPhone() {
super("SmartPhone");
setUndecorated(true);
setBackground(new Color(1f, 1f, 1f, .5f));
setSize(FRAME_WIDTH, FRAME_HEIGHT);
init(); start();
device = this;
}
这是我的构造函数。 init()
是创建布局的方法,start()
是添加 MouseAdapter
.
的方法
我的setBackground()
有什么问题吗?
在CardLayout
中切换组件时,使用CardLayout.show()
方法,不要直接使用setVisible()
。像这样:
CardLayout cardLayout = new CardLayout();
JPanel cardPanel = new JPanel(cardLayout);
String oneStr = "One";
String twoStr = "Two";
JLabel oneLabel = new JLabel(oneStr);
JLabel twoLabel = new JLabel(twoStr);
cardPanel.add(oneLabel, oneStr);
cardPanel.add(twoLabel, twoStr);
cardLayout.show(cardPanel, oneStr);//sets "One" visible
cardLayout.show(cardPanel, twoStr);//sets "Two" visible
看这里:http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
嗯...解决了..?
我不知道我做了什么,但是在做了一些其他项目之后,
组件打印得很好..!
好的..我正在重写这个问题..
我发现 setUndecorated()
不是问题所在。
问题是setBackground(new Color(0, 0, 0, 0)
经过一些尝试,CardLayout
显示了正确的结果
当背景的 Alpha 通道为 1(完全不透明)时。
否则显示错误结果。
public SmartPhone() {
super("SmartPhone");
setUndecorated(true);
setBackground(new Color(1f, 1f, 1f, .5f));
setSize(FRAME_WIDTH, FRAME_HEIGHT);
init(); start();
device = this;
}
这是我的构造函数。 init()
是创建布局的方法,start()
是添加 MouseAdapter
.
我的setBackground()
有什么问题吗?
在CardLayout
中切换组件时,使用CardLayout.show()
方法,不要直接使用setVisible()
。像这样:
CardLayout cardLayout = new CardLayout();
JPanel cardPanel = new JPanel(cardLayout);
String oneStr = "One";
String twoStr = "Two";
JLabel oneLabel = new JLabel(oneStr);
JLabel twoLabel = new JLabel(twoStr);
cardPanel.add(oneLabel, oneStr);
cardPanel.add(twoLabel, twoStr);
cardLayout.show(cardPanel, oneStr);//sets "One" visible
cardLayout.show(cardPanel, twoStr);//sets "Two" visible
看这里:http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
嗯...解决了..?
我不知道我做了什么,但是在做了一些其他项目之后,
组件打印得很好..!