Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window decorations: "full window content" mode #801

Merged
merged 3 commits into from Feb 19, 2024

Conversation

DevCharly
Copy link
Collaborator

This PR brings "full window content" mode to FlatLaf window decorations on Windows 10/11 (and on Linux). For macOS see here.

Full window content mode allows you to extend the content into the window title bar. This means that the content pane (and glass pane) of the Swing window is extended into the window title bar. The window icon and title are automatically hidden. Only the minimize/maximize/close buttons stay visible. So your application can use (nearly) the whole window area.

The top area (same height as minimize/maximize/close buttons) can still be used to move the window (click-and-drag), maximize window (double-click), or show window menu (right-click). FlatLaf automatically detects components in that area that process mouse events and excludes them.

You can try out "full window content" mode in FlatLaf Demo.
Press the "expand" button on the right side in the tab area (see red arrow):

grafik

The menu bar and toolbar are hidden (from the Demo; not automatically) so that the tabbed pane moves into the title bar area:

grafik

Note: If your application uses/requires a menu bar, it usually makes not much sense to use full window content mode.

How to enable

frame.getRootPane().putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT, true );

Buttons placeholder

To avoid that your components are overlapped by the minimize/maximize/close buttons, you need to add some placeholder component to the layout of your application. For Windows in the top-right corner (or top-left for right-to-left component orientation). A buttons placeholder is a JPanel that has client property FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER set.

Note that FlatLaf controls the preferred size of the placeholder panel. If fullWindowContent mode is enabled, it gets the size of the buttons area. Otherwise, the preferred size is 0, 0, which hides the placeholder.

JPanel placeholder = new JPanel();
placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "win" );

If you have a toolbar at top of your frame, use an additional panel that contains placeholder at EAST (or LINE_END) and toolbar in CENTER:

JToolBar toolBar = new JToolBar();
// add tool bar items

JPanel toolBarPanel = new JPanel( new BorderLayout() );
toolBarPanel.add( toolBar, BorderLayout.CENTER );
toolBarPanel.add( placeholder, BorderLayout.LINE_END );

frame.getContentPane().add( toolBarPanel, BorderLayout.NORTH );

See FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER javadoc for details.

For testing, you can make the placeholder "visible" with:

UIManager.put( "FlatLaf.debug.panel.showPlaceholders", true );

grafik

The red figure shows that placeholder bounds, the magenta figure the buttons bounds.

macOS

See https://www.formdev.com/flatlaf/macos/#full_window_content for details on how to enable full window content mode on macOS, which is provided by Java. See also PR #779 for larger close/minimize/zoom buttons spacing and usage of placeholder on macOS.

@DevCharly
Copy link
Collaborator Author

A snapshot for this PR is now available.
Use PR-801-SNAPSHOT as version.
https://github.com/JFormDesigner/FlatLaf#snapshots

@DevCharly DevCharly mentioned this pull request Feb 5, 2024
@DevCharly DevCharly linked an issue Feb 5, 2024 that may be closed by this pull request
- fixed updating of client property `FULL_WINDOW_CONTENT_BUTTONS_BOUNDS` when resizing window
- fixed title bar buttons placeholder debug painting
@DevCharly DevCharly merged commit fbdc8d5 into main Feb 19, 2024
7 checks passed
@DevCharly DevCharly added this to the 3.4 milestone Feb 19, 2024
@DevCharly DevCharly deleted the windows-full-window-content branch February 20, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Customizable title bar
1 participant