不幸的是,我不能说你是如何实现全屏应用的。但是,我尝试了一些东西,这个想出了:
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Gui extends JFrame {
public Gui() {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
// Set some charateristics of the frame
this.setExtendedState(Frame.MAXIMIZED_BOTH);
this.setBackground(Color.black);
this.setUndecorated(true);
JButton a = new JButton("PRESS ME!");
a.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser fc = new JFileChooser();
fc.showOpenDialog(getParent());
}
});
this.add(a);
this.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Gui();
}
});
}
}
注重事实,我创建了一个新的JFileChooser与当前的JFrame作为参数的父。
编辑: 我现在甚至试图设置
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(new Gui());
并没有
this.setUndecorated(true);
它为我工作(有一个不错的全屏视图和JFileChooser的是在前面) 。我相信窗口装饰的问题与我的窗口管理器(我使用linux和gnome)相关联。
希望这个解决方案对你有用,如果没有的话: 你能解释一点点,你如何创建全屏应用?
为什么'setExtendedState(JFrame.MAXIMIZED_BOTH)'而不是? – trashgod
因为最大化的窗口不是全屏窗口 - Windows任务栏在那里,我不想要它 – bagage
我很少使用全屏幕,从来没有注意到这种效果。您可以编辑您的问题以阐明需求,确定目标平台,并包含显示您当前方法的[最小,完整,测试和可读示例*](http://stackoverflow.com/help/mcve)。 – trashgod