我有這樣的代碼,基本上初始化一個新的JFrame,並將其設置全屏全屏幕邊框的問題
public class FullScreenFrameTest extends JFrame {
public FullScreenFrameTest() {
super();
initFrame();
setVisible(true);
//full screen
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
device.setFullScreenWindow(this);
//end full screen
}
public void initFrame() {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setUndecorated(true);
setLocation(0, 0); //tried removing this, still doesn't work
setSize(screen.width, screen.height);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
new FullScreenFrameTest();
}
}
的問題是,有時它的工作,有時沒有,尤其是與Ubuntu:有時我會看到全屏,有時會顯示兩個條。我錯過了什麼?
UPDATE
有一個截圖:
[''invokeLater()'](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html)? –
1)應該在EDT上創建和更新Java GUI。有關更多詳細信息,請參見[Swing中的併發](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/)。 2)另請參見['Frame.setExtendedState(INT)'](http://docs.oracle.com/javase/7/docs/api/java/awt/Frame.html#setExtendedState%28int%29)。 –
@CatalinaIsland它的工作,謝謝! – BackSlash