Java Code Examples for javax.swing.JRootPane

The following examples show how to use javax.swing.JRootPane. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: FlatLaf   Source File: FlatTitlePane.java    License: Apache License 2.0 6 votes vote down vote up
protected void frameStateChanged() {
	if( window == null || rootPane.getWindowDecorationStyle() != JRootPane.FRAME )
		return;

	if( window instanceof Frame ) {
		Frame frame = (Frame) window;
		boolean resizable = frame.isResizable();
		boolean maximized = ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0);

		iconifyButton.setVisible( true );
		maximizeButton.setVisible( resizable && !maximized );
		restoreButton.setVisible( resizable && maximized );
	} else {
		// hide buttons because they are only supported in frames
		iconifyButton.setVisible( false );
		maximizeButton.setVisible( false );
		restoreButton.setVisible( false );

		revalidate();
		repaint();
	}
}
 
Example 2
Source Project: littleluck   Source File: LuckMetalRootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
protected void installTitlePane(JRootPane root, LuckTitlePanel titlePane, Window window)
{
    JLayeredPane layeredPane = root.getLayeredPane();

    JComponent oldTitlePane = getTitlePane();

    if (oldTitlePane != null)
    {
        oldTitlePane.setVisible(false);

        layeredPane.remove(oldTitlePane);
    }

    if (titlePane != null)
    {
    	titlePane.setOpaque(true);
    	
        layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);

        titlePane.setVisible(true);
    }

    this.titlePane = titlePane;
}
 
Example 3
/**
 * Manage low level key strokes ESCAPE : Close the window
 *
 * @return
 */
protected JRootPane createRootPane() {
	JRootPane rootPane = new JRootPane();
	KeyStroke strokeEscape = KeyStroke.getKeyStroke("ESCAPE");

	@SuppressWarnings("serial")
	Action actionListener = new AbstractAction() {
		public void actionPerformed(ActionEvent actionEvent) {
			setVisible(false);
		}
	};

	InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	inputMap.put(strokeEscape, "ESCAPE");
	rootPane.getActionMap().put("ESCAPE", actionListener);

	return rootPane;
}
 
Example 4
Source Project: beautyeye   Source File: BERootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Uninstalls any state that <code>installClientDecorations</code> has
 * installed.
 * <p>
 * NOTE: This may be called if you haven't installed client decorations
 * yet (ie before <code>installClientDecorations</code> has been invoked).
 *
 * @param root the root
 */
private void uninstallClientDecorations(JRootPane root) 
{
	uninstallBorder(root);
	uninstallWindowListeners(root);
	setTitlePane(root, null);
	uninstallLayout(root);
	// We have to revalidate/repaint root if the style is JRootPane.NONE
	// only. When we needs to call revalidate/repaint with other styles
	// the installClientDecorations is always called after this method
	// imediatly and it will cause the revalidate/repaint at the proper
	// time.
	int style = root.getWindowDecorationStyle();
	if (style == JRootPane.NONE) 
	{
		root.repaint();
		root.revalidate();
	}
	// Reset the cursor, as we may have changed it to a resize cursor
	if (window != null) 
	{
		window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
	}
	window = null;
}
 
Example 5
Source Project: visualvm   Source File: WindowBuilders.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame createInstanceImpl() {
    JInternalFrame frame = new JInternalFrame(title, resizable, closable, maximizable, iconable) {
        protected JRootPane createRootPane() {
            return _rootPane == null ? null : _rootPane.createInstance();
        }
        public void addNotify() {
            try {
                // Doesn't seem to work correctly
                setClosed(_isClosed);
                setMaximum(_isMaximum);
                setIcon(_isIcon);
                setSelected(_isSelected);
            } catch (PropertyVetoException ex) {}
        }
    };
    return frame;
}
 
Example 6
Source Project: seaglass   Source File: SeaGlassRootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Installs the necessary Listeners on the parent <code>Window</code>, if
 * there is one.
 *
 * <p>This takes the parent so that cleanup can be done from <code>
 * removeNotify</code>, at which point the parent hasn't been reset yet.</p>
 *
 * @param root   the JRootPane.
 * @param parent The parent of the JRootPane
 */
private void installWindowListeners(JRootPane root, Component parent) {
    if (parent instanceof Window) {
        window = (Window) parent;
    } else {
        window = SwingUtilities.getWindowAncestor(parent);
    }

    if (window != null) {
        if (mouseInputListener == null) {
            mouseInputListener = createWindowMouseInputListener(root);
        }

        window.addMouseListener(mouseInputListener);
        window.addMouseMotionListener(mouseInputListener);
        if (windowListener == null) {
            windowListener = createFocusListener();
            window.addWindowListener(windowListener);
        }
    }
}
 
Example 7
Source Project: netbeans   Source File: ResizeGestureRecognizer.java    License: Apache License 2.0 6 votes vote down vote up
private void resetState() {
    state = STATE_NOOP;
    JRootPane pane = SwingUtilities.getRootPane(comp);
    glass.setVisible(false);
    if (pane != null && oldGlass != null) {
        // when clicking results in hidden slide window, pne can be null?
        // how to avoid?
        JComponent current = (JComponent) pane.getGlassPane();
        if (current instanceof GlassPane) {
            pane.setGlassPane(oldGlass);
        }
    }
    if( null != comp )
        comp.setCursor(null);
    oldGlass = null;
    startPoint = null;
}
 
Example 8
Source Project: netbeans   Source File: NotificationLineSupportTest.java    License: Apache License 2.0 6 votes vote down vote up
private static JLabel findNotificationLabel (Container container) {
    for (Component component : container.getComponents ()) {
        if (component.getClass ().getName ().indexOf (NOTIFICATION_LABEL_NAME) != -1) {
            return (JLabel) component;
        }
        if (component instanceof JRootPane) {
            JRootPane rp = (JRootPane) component;
            return findNotificationLabel (rp.getContentPane ());
        }
        if (component instanceof JPanel) {
            JPanel p = (JPanel) component;
            return findNotificationLabel (p);
        }
    }
    return null;
}
 
Example 9
Source Project: Swing9patch   Source File: FloatableDialog.java    License: Apache License 2.0 6 votes vote down vote up
protected void initGUI()
	{
		// set dialog full transparent
		setUndecorated(true);
		AWTUtilities.setWindowOpaque(this, false);
		this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

		// init gui
		JPanel contentPane = new JPanel();
		contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.setOpaque(false);
		setContentPane(contentPane);
				
		// others setup
		this.setFocusable(false);
		this.setFocusableWindowState(false);
//		this.setAlwaysOnTop(true);
		this.setVisible(false);
	}
 
Example 10
Source Project: netbeans   Source File: WindowBuilders.java    License: Apache License 2.0 6 votes vote down vote up
protected JInternalFrame createInstanceImpl() {
    JInternalFrame frame = new JInternalFrame(title, resizable, closable, maximizable, iconable) {
        protected JRootPane createRootPane() {
            return _rootPane == null ? null : _rootPane.createInstance();
        }
        public void addNotify() {
            try {
                // Doesn't seem to work correctly
                setClosed(_isClosed);
                setMaximum(_isMaximum);
                setIcon(_isIcon);
                setSelected(_isSelected);
            } catch (PropertyVetoException ex) {}
        }
    };
    return frame;
}
 
Example 11
Source Project: seaglass   Source File: SeaGlassRootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the window title pane -- the JComponent used to provide a plaf a way
 * to override the native operating system's window title pane with one
 * whose look and feel are controlled by the plaf. The plaf creates and sets
 * this value; the default is null, implying a native operating system
 * window title pane.
 *
 * @param root      content the <code>JComponent</code> to use for the
 *                  window title pane.
 * @param titlePane the SeaGlassTitlePane.
 */
private void setTitlePane(JRootPane root, JComponent titlePane) {
    JLayeredPane layeredPane  = root.getLayeredPane();
    JComponent   oldTitlePane = getTitlePane();

    if (oldTitlePane != null) {
        oldTitlePane.setVisible(false);
        layeredPane.remove(oldTitlePane);
    }

    if (titlePane != null) {
        layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
        titlePane.setVisible(true);
    }

    this.titlePane = titlePane;
}
 
Example 12
Source Project: littleluck   Source File: LuckRootPaneLayout.java    License: Apache License 2.0 6 votes vote down vote up
public Dimension maximumLayoutSize(Container parent)
{
    Insets insets = parent.getInsets();

    JRootPane root = (JRootPane) parent;

    Dimension cpd = null;

    if (root.getContentPane() != null)
    {
        cpd = root.getContentPane().getMaximumSize();
    }
    else
    {
        cpd = root.getSize();
    }

    return getDimension(insets, cpd.width, cpd.height);
}
 
Example 13
private Component getLayeredPane() {
	Container parent = null;
	if (this.owner != null) {
		parent = this.owner instanceof Container ? (Container) this.owner : this.owner.getParent();
	}
	for (Container p = parent; p != null; p = p.getParent()) {
		if (p instanceof JRootPane) {
			if (p.getParent() instanceof JInternalFrame) {
				continue;
			}
			parent = ((JRootPane) p).getLayeredPane();
		} else if (p instanceof Window) {
			if (parent == null) {
				parent = p;
			}
			break;
		} else if (p instanceof JApplet) {
			break;
		}
	}
	return parent;
}
 
Example 14
Source Project: beautyeye   Source File: BERootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the window title pane -- the JComponent used to provide a plaf a
 * way to override the native operating system's window title pane with
 * one whose look and feel are controlled by the plaf.  The plaf creates
 * and sets this value; the default is null, implying a native operating
 * system window title pane.
 *
 * @param root the root
 * @param titlePane the title pane
 */
private void setTitlePane(JRootPane root, JComponent titlePane) 
{
	JLayeredPane layeredPane = root.getLayeredPane();
	JComponent oldTitlePane = getTitlePane();

	if (oldTitlePane != null)
	{
		oldTitlePane.setVisible(false);
		layeredPane.remove(oldTitlePane);
	}
	if (titlePane != null) 
	{
		layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
		titlePane.setVisible(true);
	}
	this.titlePane = titlePane;
}
 
Example 15
Source Project: ChatGameFontificator   Source File: ChatWindow.java    License: The Unlicense 6 votes vote down vote up
/**
 * Does the work required to make the parameter JDialog be hidden when pressing escape
 * 
 * @param popup
 */
public static void setupHideOnEscape(final JDialog popup)
{
    Action aa = new AbstractAction()
    {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent event)
        {
            popup.setVisible(false);
        }
    };
    final String mapKey = "escapePressed";
    JRootPane root = popup.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, mapKey);
    root.getActionMap().put(mapKey, aa);
}
 
Example 16
Source Project: seaglass   Source File: SeaGlassRootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Installs the necessary state onto the JRootPane to render client
 * decorations. This is ONLY invoked if the <code>JRootPane</code> has a
 * decoration style other than <code>JRootPane.NONE</code>.
 *
 * @param root the JRootPane.
 */
private void installClientDecorations(JRootPane root) {
    installBorder(root);
    if (root.getParent() instanceof JFrame || root.getParent() instanceof JDialog) {
        if (PlatformUtils.isMac()) {
            makeFrameBackgroundTransparent(root);
        } else {
            shapeWindow(root);
        }
    }

    JComponent titlePane = createTitlePane(root);

    setTitlePane(root, titlePane);
    installWindowListeners(root, root.getParent());
    installLayout(root);
    if (window != null) {
        root.revalidate();
        root.repaint();
    }
}
 
Example 17
Source Project: blog-codes   Source File: EditorAboutFrame.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Overrides {@link JDialog#createRootPane()} to return a root pane that
 * hides the window when the user presses the ESCAPE key.O
 */
protected JRootPane createRootPane()
{
	KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
	JRootPane rootPane = new JRootPane();
	rootPane.registerKeyboardAction(new ActionListener()
	{
		public void actionPerformed(ActionEvent actionEvent)
		{
			setVisible(false);
		}
	}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
	return rootPane;
}
 
Example 18
Source Project: openjdk-jdk9   Source File: JDialogOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JDialog.getRootPane()} through queue
 */
public JRootPane getRootPane() {
    return (runMapping(new MapAction<JRootPane>("getRootPane") {
        @Override
        public JRootPane map() {
            return ((JDialog) getSource()).getRootPane();
        }
    }));
}
 
Example 19
Source Project: FlatLaf   Source File: JBRCustomDecorations.java    License: Apache License 2.0 5 votes vote down vote up
static void install( JRootPane rootPane ) {
	if( !isSupported() )
		return;

	// check whether root pane already has a parent, which is the case when switching LaF
	if( rootPane.getParent() != null )
		return;

	// Use hierarchy listener to wait until the root pane is added to a window.
	// Enabling JBR decorations must be done very early, probably before
	// window becomes displayable (window.isDisplayable()). Tried also using
	// "ancestor" property change event on root pane, but this is invoked too late.
	HierarchyListener addListener = new HierarchyListener() {
		@Override
		public void hierarchyChanged( HierarchyEvent e ) {
			if( e.getChanged() != rootPane || (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == 0 )
				return;

			Container parent = e.getChangedParent();
			if( parent instanceof Window )
				install( (Window) parent );

			// use invokeLater to remove listener to avoid that listener
			// is removed while listener queue is processed
			EventQueue.invokeLater( () -> {
				rootPane.removeHierarchyListener( this );
			} );
		}
	};
	rootPane.addHierarchyListener( addListener );
}
 
Example 20
Source Project: gcs   Source File: Search.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private void removeFloater() {
    if (mFloater != null) {
        JRootPane rootPane = getRootPane();
        Container parent   = mFloater.getParent();
        Rectangle bounds   = mFloater.getBounds();
        UIUtilities.convertRectangle(bounds, parent, rootPane);
        if (parent != null) {
            parent.remove(mFloater);
        }
        mFloater = null;
        if (rootPane != null) {
            rootPane.repaint(bounds);
        }
    }
}
 
Example 21
Source Project: FlatLaf   Source File: FlatRootPaneUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void installUI( JComponent c ) {
	super.installUI( c );

	rootPane = (JRootPane) c;

	if( rootPane.getWindowDecorationStyle() != JRootPane.NONE )
		installClientDecorations();

	if( canUseJBRCustomDecorations )
		JBRCustomDecorations.install( rootPane );
}
 
Example 22
Source Project: beautyeye   Source File: BERootPaneUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Uninstalls the previously installed <code>LayoutManager</code>.
 *
 * @param root the root
 */
private void uninstallLayout(JRootPane root) 
{
	if (savedOldLayout != null) 
	{
		root.setLayout(savedOldLayout);
		savedOldLayout = null;
	}
}
 
Example 23
Source Project: javamelody   Source File: ShadowPopupFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return the top level layered pane which contains the owner.
 */
private Container getLayeredPane() {
	// The code below is copied from PopupFactory#LightWeightPopup#show()
	Container parent = null;
	if (owner != null) {
		parent = owner instanceof Container ? (Container) owner : owner.getParent();
	}
	// Try to find a JLayeredPane and Window to add
	for (Container p = parent; p != null; p = p.getParent()) {
		if (p instanceof JRootPane) {
			if (p.getParent() instanceof JInternalFrame) {
				continue;
			}
			parent = ((JRootPane) p).getLayeredPane();
			// Continue, so that if there is a higher JRootPane, we'll
			// pick it up.
		} else if (p instanceof Window) {
			if (parent == null) {
				parent = p;
			}
			break;
		} else if (p instanceof JApplet) {
			// Painting code stops at Applets, we don't want
			// to add to a Component above an Applet otherwise
			// you'll never see it painted.
			break;
		}
	}
	return parent;
}
 
Example 24
/**
 * Constructs a Swing based input method window.
 */
public InputMethodJFrame(String title, InputContext context) {
    super(title);
    //InputMethodJFrame never has LookAndFeel decoration
    if(JFrame.isDefaultLookAndFeelDecorated())
    {
       this.setUndecorated(true);
       this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
    }
    if (context != null) {
        this.inputContext = context;
    }
    setFocusableWindowState(false);
}
 
Example 25
Source Project: hottub   Source File: InputMethodJFrame.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Swing based input method window.
 */
public InputMethodJFrame(String title, InputContext context) {
    super(title);
    //InputMethodJFrame never has LookAndFeel decoration
    if(JFrame.isDefaultLookAndFeelDecorated())
    {
       this.setUndecorated(true);
       this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
    }
    if (context != null) {
        this.inputContext = context;
    }
    setFocusableWindowState(false);
}
 
Example 26
Source Project: bigtable-sql   Source File: OkClosePanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
	 * Make the OK button the default. This should be called
	 * <EM>after</EM> you add this panel to a dialog/frame, not
	 * before otherwise you will get an <TT>IllegalStateException</TT>
	 * exception.
	 *
	 * @param	IllegalStateException
	 * 			Thrown if <TT>null</TT> <TT>JRootPane</TT>. I.E. component
	 * 			hasn't been added to a frame, dialog etc.
	 */
	public synchronized void makeOKButtonDefault()
			throws IllegalStateException
	{
		JRootPane root = getRootPane();
		if (root == null)
		{
			throw new IllegalStateException("Null RootPane so cannot set default button");
		}
//		root.setDefaultButton(_okBtn);
	}
 
Example 27
Source Project: jpexs-decompiler   Source File: View.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JDialog dialog) {
    Action dispatchClosing = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(
                    dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
            escapeStroke, dispatchWindowClosingActionMapKey);
    root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
}
 
Example 28
Source Project: openjdk-8   Source File: InputMethodJFrame.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a Swing based input method window.
 */
public InputMethodJFrame(String title, InputContext context) {
    super(title);
    //InputMethodJFrame never has LookAndFeel decoration
    if(JFrame.isDefaultLookAndFeelDecorated())
    {
       this.setUndecorated(true);
       this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
    }
    if (context != null) {
        this.inputContext = context;
    }
    setFocusableWindowState(false);
}
 
Example 29
Source Project: SubTitleSearcher   Source File: ExtractDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected JRootPane createRootPane() {
	KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
	JRootPane rootPane = new JRootPane();
	rootPane.registerKeyboardAction(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			escapeKeyProc();
		}
	}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

	return rootPane;
}
 
Example 30
Source Project: SubTitleSearcher   Source File: AboutDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected JRootPane createRootPane() {
	KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
	JRootPane rootPane = new JRootPane();
	rootPane.registerKeyboardAction(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			escapeKeyProc();
		}
	}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

	return rootPane;
}