JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.45k stars 274 forks source link

JOptionPane scales incorrectly when zooming #256

Closed Blanco27 closed 3 years ago

Blanco27 commented 3 years ago

image

We are on a Windows 10 with 200% system zoom. We are running openJDK 11 and flatlaf 1.0rc1 (afaik this hasn't aleady been fied with rc2/rc3). The monitor is 4k.

DevCharly commented 3 years ago

Hmm, can't reproduce here...

I think the problem comes from the wrapped message, because the dialog width is correct, but not the height.

Is this HTML text in the message? Or a custom control?

Bios-Marcel commented 3 years ago

Nah, simple text message with a default option pane. Might it be relevant that we are using remotedesktop? The zoom on the host and client might differ, is flatlaf able to retrieve the correct value in this situation?

DevCharly commented 3 years ago

Nah, simple text message...

Are you sure? There is a bold '6' in the text 😉

Don't think that FlatLaf is involved in computing dialog size. This is standard Swing layout calculation.

Bios-Marcel commented 3 years ago

I am sorry, you are right for this specific dialog. I thought of a different dialog when I said no. I noticed there's more dialogs that have this problem. Some of which don't use any HTML. Meaning there's also no <html> at the start or end of the string.

However, we are creating them in a "non standard" way:

    final JOptionPane pane = new JOptionPane( message, messageType, optionType, icon, options, initialValue )
    {
      @Override
      public int getMaxCharactersPerLineCount()
      {
        return narrowness;
      }
    };

    final JDialog dialog = pane.createDialog( parentComponent, title );

Might that be related?

@MioBlanco can you see whether there are any dialogs that work?

DevCharly commented 3 years ago

Don't think that this makes a difference.

BTW FlatLaf supports maxCharactersPerLine option out-of-the-box. The default value is 80 characters. You can assign a different value with:

UIManager.put( "OptionPane.maxCharactersPerLine", 60 );

If JOptionPane.getMaxCharactersPerLineCount() returns a value greater than zero, then this value is used.

So if you don't use other Lafs, you can try to create option panes in a "standard way" and check whether this makes a difference.

DevCharly commented 3 years ago

Can you please try the FlatLaf Demo (with the same JRE as your app) and check whether the option panes on the "Option Pane" tab have correct sizes? Also try to click on "Show dialog" links to check whether option dialogs have correct sizes?

Blanco27 commented 3 years ago

Okay, so we are able to constantly reproduce this with our application. However we can't seem to reproduce it with the flatlaf demo application.

Steps to reproduce:

  1. Start your machine
  2. Set zoom to 100% (no zoom)
  3. Start your application
  4. Go to a second machine
  5. Set zoom on the second machine to 200%
  6. Connect to first machine
  7. Open dialog
  8. Bug

Switching between themes while the applicaton is still running doesn't seem to "fix" the incorrect sizing.

Blanco27 commented 3 years ago

Also reproducible using this demo:

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;

import com.formdev.flatlaf.FlatLightLaf;

public class OptionPaneTest
{
  public static void main( final String[] args )
  {
    FlatLightLaf.install();

    final JFrame frame = new JFrame();
    final JButton button = new JButton( "Click me" );
    button.addActionListener( __ ->
    {
      showDialog( frame );
    } );
    frame.add( button );
    frame.setSize( 400, 300 );
    frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
    frame.setLocationRelativeTo( null );
    frame.setVisible( true );

  }

  private static void showDialog( final JFrame frame )
  {
    final String[] options = { "Ja", "Nein" };
    final String initialValue = options[ 1 ];
    final JOptionPane pane =
        new JOptionPane( "Wollen Sie sich wirklich abmelden?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options,
            initialValue )
        {
          @Override
          public int getMaxCharactersPerLineCount()
          {
            return Integer.MAX_VALUE;
          }
        };

    final JDialog dialog = pane.createDialog( frame, "Abmelden" );
    dialog.setVisible( true );
  }
}
DevCharly commented 3 years ago

@MioBlanco thanks for the detailed steps and the code.

Unfortunately the problem does not show up on my machines. Used Windows 10 Remote Desktop to connect two PCs.

And the issue happens only if you start the app on the first machine and then connect from the second one? When you start the app while already connected, it works?

Could you post a screenshot made with your code snippet?

DevCharly commented 3 years ago

Does it work for other Lafs? Windows Laf or Metal?

Blanco27 commented 3 years ago

And the issue happens only if you start the app on the first machine and then connect from the second one? When you start the app while already connected, it works?

Yes thats the only way I managed to reproduce it.

I tested it on Windows and Metal Laf and here are my results: yEFoTl3izo 3sv6YgquDH 89d4l5FzDY

As you can see it looks kinda weird on all lafs, so it might a java bug.

DevCharly commented 3 years ago

Thx.

What is the exact Java version that you use? You're using ojdkbuild, right?

And this problem occurs only for option panes? Not for "normal" dialogs?

Blanco27 commented 3 years ago

I used ojkdbuild 11.0.10.9-1.

It only appeared on optionspanes, but I tested ojkdbuild 14.0.2.12-1 by now and I couldn't reproduce it there, so I assume they fixed it already.

DevCharly commented 3 years ago

Can now reproduce it, but with a different scenario:

  1. connect a second screen
  2. primary screen at 100%
  3. secondary at 175%
  4. start OptionPaneTest on primary
  5. move to secondary
  6. open option pane --> bug

Seems that the difference between the two scaling factors affect the option pane size, because when I change primary to 150%, then option pane is also too small, but not much:

image

DevCharly commented 3 years ago

Seems that the problem does not occur in OpenJDK 12 - 14, but is back in 15 😒

Blanco27 commented 3 years ago

I tried it myself and yes, the bug is back in 15 indeed. And your way to reproduce it saves quite a lot of time 😄

DevCharly commented 3 years ago

Seems that some change made in Java 15, which causes the problem, was then back-ported to Java 11.0.8. OpenJDK 11.0.2, 10.0.2 work fine. AdoptOpenJDK 11.0.7 is also ok, but 11.0.8 has the problem...

Bios-Marcel commented 3 years ago

Gotta love big scale software development ^^

DevCharly commented 3 years ago

Have re-tested the issue and it turns out that it is fixed since FlatLaf 1.1, which introduced native window decorations on Windows.

When disabling native window decorations (TitlePane.useWindowDecorations = false), it is still there. Even in OpenJDK 17.0.1.

Closing because it is a issue in OpenJDK...