Skip to content

Zooming API#1051

Merged
DevCharly merged 1 commit intomainfrom
zooming
Nov 25, 2025
Merged

Zooming API#1051
DevCharly merged 1 commit intomainfrom
zooming

Conversation

@DevCharly
Copy link
Copy Markdown
Collaborator

@DevCharly DevCharly commented Oct 26, 2025

The zooming API makes makes it easier to supports zooming in applications.
Zooming is done by increasing/decreasing FlatLaf scale factor (see UIScale.getUserScaleFactor())
and increasing/decreasing default font size.

Note:

  • This PR only offers API. You need to implement zooming UI for your application yourself.
  • Only standard Swing components are zoomed.
    Custom components need to use UIScale.scale(int) to zoom their UI.

Use FlatLaf Demo to test it:

image

with 120% zoom:

image

Usage

Set zoom factor

if( UIScale.setZoomFactor( 1.2f ) )
    FlatLaf.updateUI();

UI needs to be updated if zoom factor has changed.
If you set zoom factor before any UI components are created, then FlatLaf.updateUI() is not necessary.

Increase zoom factor / Zoom In

if( UIScale.zoomIn() )
    FlatLaf.updateUI();

This increases zoom factor using next greater factor in supported factors array.

Decrease zoom factor / Zoom Out

if( UIScale.zoomOut() )
    FlatLaf.updateUI();

This decreases zoom factor using next smaller factor in supported factors array.

Reset Zoom

if( UIScale.zoomReset() )
    FlatLaf.updateUI();

Resets zoom factor to 1.

Define supported zoom factors for zoom in/out

UIScale.setSupportedZoomFactors( new float[] { 1f, 1.1f, 1.25f, 1.5f, 1.75f, 2f } );

Sets the supported zoom factors used for zoomIn() and zoomOut().
Default is [ 1f, 1.1f, 1.25f, 1.5f, 1.75f, 2f ].

@DevCharly DevCharly added this to the 3.7 milestone Oct 26, 2025
@DevCharly
Copy link
Copy Markdown
Collaborator Author

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

Prebuilt binaries (Artifacts) are available here (requires GitHub login):
https://github.com/JFormDesigner/FlatLaf/actions/runs/18821581715

@DJ-Raven
Copy link
Copy Markdown
Contributor

Decrease zoom factor / Zoom Out
if( UIScale.zoomIn() )
FlatLaf.updateUI();

I thing you mean:

if( UIScale.zoomOut() )
    FlatLaf.updateUI();

Thank you for new API

@DevCharly
Copy link
Copy Markdown
Collaborator Author

@DJ-Raven thanks.

Fixed and added zoomReset() and some descriptions.

@DevCharly DevCharly merged commit 02636b2 into main Nov 25, 2025
8 checks passed
@DevCharly DevCharly deleted the zooming branch November 25, 2025 17:26
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.

2 participants