1

我正在使用以下代码从我的 Eclipse 插件创建全屏 JFrame。显示了 JFrame,但我看不到我的按钮。我不知道为什么不:

public class MainFrame extends JFrame {

    private static final long serialVersionUID = 1L;

    public MainFrame() {
        super();

        createComponents();
        setFullScreen();

        this.setVisible(true);
    }

    private void createComponents() {
        System.out.println("Create components");
        JButton exit = new JButton("Exit");

        exit.setVisible(true);
        exit.setBackground(Color.YELLOW);
        exit.setSize(new Dimension(500, 500));
        exit.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                System.out.println("Exit by button");
                System.exit(0);
            }
        });

        this.setBackground(Color.RED);


        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(exit, BorderLayout.CENTER);
    }

    private void setFullScreen() {

        this.setResizable(false);
        this.setUndecorated(true);
        this.setAlwaysOnTop(true);

        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();

        devices[0].setFullScreenWindow(this);
    }

}
4

1 回答 1

3

供参考,FullScreenTest是一个工作示例。

附录:因为 Eclipse 插件必须使用 SWT,所以您可以尝试Full Screen your RCP Applications中显示的方法。还提到了最大化运行的替代方案。

于 2012-04-07T20:32:33.120 回答