Example usage for javax.swing JWindow setContentPane

List of usage examples for javax.swing JWindow setContentPane

Introduction

In this page you can find the example usage for javax.swing JWindow setContentPane.

Prototype

@BeanProperty(bound = false, hidden = true, description = "The client area of the window where child components are normally inserted.")
public void setContentPane(Container contentPane) 

Source Link

Document

Sets the contentPane property for this window.

Usage

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

private void menuFullScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFullScreenActionPerformed
    final Component currentComponent = this.tabPane.getSelectedComponent();
    if (!(currentComponent instanceof Container)) {
        LOGGER.warn("Detected attempt to full screen not a container : " + currentComponent);
        return;//from w  w  w. j  a  v a  2s. c  o m
    }

    final GraphicsConfiguration gconfig = this.getGraphicsConfiguration();
    if (gconfig != null) {
        final GraphicsDevice device = gconfig.getDevice();
        if (device.isFullScreenSupported()) {
            if (device.getFullScreenWindow() == null) {
                final JLabel label = new JLabel("Opened in full screen");
                final int tabIndex = this.tabPane.getSelectedIndex();
                this.tabPane.setComponentAt(tabIndex, label);
                final JWindow window = new JWindow(Main.getApplicationFrame());
                window.setAlwaysOnTop(true);
                window.setContentPane((Container) currentComponent);

                endFullScreenIfActive();

                final KeyEventDispatcher fullScreenEscCatcher = new KeyEventDispatcher() {
                    @Override
                    public boolean dispatchKeyEvent(@Nonnull final KeyEvent e) {
                        if (e.getID() == KeyEvent.KEY_PRESSED && (e.getKeyCode() == KeyEvent.VK_ESCAPE
                                || e.getKeyCode() == KeyEvent.VK_F11)) {
                            endFullScreenIfActive();
                            return true;
                        }
                        return false;
                    }
                };

                if (this.taskToEndFullScreen.compareAndSet(null, new Runnable() {
                    @Override
                    public void run() {
                        try {
                            window.dispose();
                        } finally {
                            tabPane.setComponentAt(tabIndex, currentComponent);
                            device.setFullScreenWindow(null);
                            KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                    .removeKeyEventDispatcher(fullScreenEscCatcher);
                        }
                    }
                })) {
                    try {
                        KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                .addKeyEventDispatcher(fullScreenEscCatcher);
                        device.setFullScreenWindow(window);
                    } catch (Exception ex) {
                        LOGGER.error("Can't turn on full screen", ex);
                        endFullScreenIfActive();
                        KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                .removeKeyEventDispatcher(fullScreenEscCatcher);
                    }
                } else {
                    LOGGER.error("Unexpected state, processor is not null!");
                }
            } else {
                LOGGER.warn("Attempt to full screen device which already in full screen!");
            }
        } else {
            LOGGER.warn("Device doesn's support full screen");
            DialogProviderManager.getInstance().getDialogProvider()
                    .msgWarn("The Device doesn't support full-screen mode!");
        }
    } else {
        LOGGER.warn("Can't find graphics config for the frame");
    }
}