全屏框架问题 [英] Full screen frame issue
本文介绍了全屏框架问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,基本上可以初始化一个新的JFrame并将其设置为全屏显示
I have this code, which basically initializes a new JFrame and sets it full screen
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上:有时我会全屏查看它,有时会显示两个条.我想念什么?
The problem is that it sometimes it does work and sometimes it doesn't, especially with Ubuntu: sometimes i see it full screen, sometimes the two bars are shown. What am i missing?
更新
有一个屏幕截图:
推荐答案
Make sure to build your GUI on the event dispatch thread with invokeLater()
.
更新:这是一个 SSCCE ,它似乎可以正常工作.
Update: Here's an SSCCE that seems to work consistently.
import java.awt.EventQueue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class FullScreenFrameTest extends JFrame {
public FullScreenFrameTest() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setUndecorated(true);
add(new JLabel("Test", JLabel.CENTER));
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
device.setFullScreenWindow(this);
setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new FullScreenFrameTest();
}
});
}
}
这篇关于全屏框架问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文