简体   繁体   English

setBackground是未修饰的JFrame

[英]setBackground is undecorated JFrame

Okay.. I'm rewriting this question.. 好吧..我正在重写这个问题..

I've found out that setUndecorated() was not the problem. 我发现setUndecorated()不是问题。

The problem was setBackground(new Color(0, 0, 0, 0) 问题是setBackground(new Color(0, 0, 0, 0)

After some tries, the the CardLayout was showing the right result 经过一番尝试后, CardLayout显示了正确的结果

when the alpha channel of the background was 1 (fully opaque). 当背景的Alpha通道为1(完全不透明)时。

And else it was showing the wrong result. 否则,它显示错误的结果。

public SmartPhone() {
    super("SmartPhone");

    setUndecorated(true); 
    setBackground(new Color(1f, 1f, 1f, .5f));

    setSize(FRAME_WIDTH, FRAME_HEIGHT);
    init(); start();

    device = this;
}

This is my constructor. 这是我的构造函数。 init() is method creating the layout and start() is the method adding MouseAdapter . init()是创建布局的方法, start()是添加MouseAdapter的方法。

Is there anything wrong with my setBackground() ? 我的setBackground()有什么问题吗?

When switching between components in a CardLayout , use the CardLayout.show() method, don't use setVisible() directly. CardLayout组件之间切换时,请使用CardLayout.show()方法,不要直接使用setVisible() Like this: 像这样:

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

See here: http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html 参见此处: http : //docs.oracle.com/javase/tutorial/uiswing/layout/card.html

Um... Solved..? 嗯...解决了吗?

I don't know what I did, but after doing some other project, 我不知道我做了什么,但是在完成其他项目之后,

Components were printed well..! 组件打印得很好..!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM