我只是进入GUI编程,慢慢学习。Java GUI编程:设置前台/后台
但是我遇到了蝙蝠的问题。我无法在我的窗口中获取Fore/Background颜色。
但是,当我通过JLabel添加标签,然后使用setFore/Back时,它们改变颜色就好了。只是不是整个窗口。
我以为.setForeground和.setBackground应该改变窗口的颜色?
import javax.swing.*;
import java.awt.*;
public class MyWindow {
public static void main(String args[])
{
Runnable init = new Runnable()
{
public void run()
{
JFrame myWindow = new JFrame("Hola!");
myWindow.setForeground(Color.YELLOW);
myWindow.setBackground(Color.YELLOW);
myWindow.setSize(400, 300);
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setLayout(null);
myWindow.setVisible(true);
}
};
SwingUtilities.invokeLater(init);
}
}
这里是各种挥杆层的解释,这可能有助于解释这种现象:http://download.oracle.com/javase/tutorial/uiswing/组件/ toplevel.html – Sean
对不起,没有看到编辑时,我张贴 – Sean