我该怎么做全屏Java中的OSX [英] How can I do full screen in Java on OSX
问题描述
我一直在尝试和失败使用java全屏模式下OSX系统的主屏幕上。无论我试过我似乎无法摆脱从显示屏顶部的苹果菜单栏。我真的需要绘制整个屏幕。谁能告诉我如何摆脱菜单?
我已经附加其表现出的问题的示例类 - 我的系统上的菜单仍可见,我希望看到一个完全空白的屏幕
进口java.awt中的*。
java.awt.event中导入*。
进口javax.swing.JFrame中;公共类FullScreenFrame扩展JFrame中实现的KeyListener { 公共FullScreenFrame(){
addKeyListener(本);
setUndecorated(真);
GraphicsDevice的GD = GraphicsEnvironment.getLocalGraphicsEnvironment()getDefaultScreenDevice()。 如果(gd.isFullScreenSupported()){
尝试{
gd.setFullScreenWindow(本);
}
最后{
gd.setFullScreenWindow(NULL);
}
}
其他{
通信System.err.println(全屏幕不支持);
} 调用setVisible(真);
} 公共无效的keyTyped(KeyEvent的E){}
公共无效键pressed(KeyEvent的E){}
公共无效调用keyReleased(KeyEvent的E){
调用setVisible(假);
处置();
} 公共静态无效的主要(字串[] args){
新FullScreenFrame();
}
}
我觉得你的问题是在这里:
{尝试
gd.setFullScreenWindow(本);
}
最后{
gd.setFullScreenWindow(NULL);
}
最后
块总是执行,因此,这里所发生的是,你的窗口变为全屏进行短暂瞬间(如果),然后立即放弃屏幕。
此外,调用setVisible(真)
是没有必要的,当你有previously名为 setFullScreenWindow(本)
根据<一href=\"http://java.sun.com/javase/6/docs/api/java/awt/GraphicsDevice.html#setFullScreenWindow%28java.awt.Window%29\">Javadocs.
因此,我想构造改成这样:
公共FullScreenFrame(){
addKeyListener(本); GraphicsDevice的GD =
。GraphicsEnvironment.getLocalGraphicsEnvironment()getDefaultScreenDevice(); 如果(gd.isFullScreenSupported()){
setUndecorated(真);
gd.setFullScreenWindow(本);
}其他{
通信System.err.println(全屏幕不支持);
的setSize(100,100); //只是一些让你看到窗口
调用setVisible(真);
}
}
I've been trying and failing to use the java full screen mode on the primary display of an OSX system. Whatever I've tried I can't seem to get rid of the 'apple' menu bar from the top of the display. I really need to paint over the entire screen. Can anyone tell me how to get rid of the menu?
I've attached an example class which exhibits the problem - on my system the menu is still visible where I would expect to see a completely blank screen.
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
public class FullScreenFrame extends JFrame implements KeyListener {
public FullScreenFrame () {
addKeyListener(this);
setUndecorated(true);
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (gd.isFullScreenSupported()) {
try {
gd.setFullScreenWindow(this);
}
finally {
gd.setFullScreenWindow(null);
}
}
else {
System.err.println("Full screen not supported");
}
setVisible(true);
}
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {
setVisible(false);
dispose();
}
public static void main (String [] args) {
new FullScreenFrame();
}
}
I think your problem is here:
try {
gd.setFullScreenWindow(this);
}
finally {
gd.setFullScreenWindow(null);
}
finally
blocks are always executed, so what happens here is that you window becomes full screen for a brief instant (if that) and then relinquishes the screen immediately.
Also, setVisible(true)
is not necessary when you have previously called setFullScreenWindow(this)
, according to the Javadocs.
So I would change the constructor to this:
public FullScreenFrame() {
addKeyListener(this);
GraphicsDevice gd =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (gd.isFullScreenSupported()) {
setUndecorated(true);
gd.setFullScreenWindow(this);
} else {
System.err.println("Full screen not supported");
setSize(100, 100); // just something to let you see the window
setVisible(true);
}
}
这篇关于我该怎么做全屏Java中的OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!