1

I have a Java Swing app with some javaFX features. I am using Java 8.

I have some troubles with "scale and layout settings", if the "size of text, apps and other items" is 100% everything works fine. But if the percentage is 150% (which is the recommended size for my pc) as soon as this instruction is run:

PlatformImpl.startup

It seems that the "internal layout" of my app changes to 100%.

Is there anyone with the same problem? Is there a way to set the scale percentage (and maybe a way to retrieve it beforehand)?

EDIT:

I am using the latest jre/jdk 8 available (1.8 update 311)

Here is a minimal reproducible example:


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.sun.javafx.application.PlatformImpl;

import javafx.application.Platform;

public class JavaFXTest {

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton btn = new JButton();

        btn.addActionListener(e ->
            //This is the culprit
            PlatformImpl.startup(() -> System.out.println("javaFX started"))
        );

        JPanel panel = new JPanel();

        JLabel label = new JLabel("Some character for testing");

        panel.add(btn);
        panel.add(label);

        frame.getContentPane().add(panel);

        // Display the window.
        frame.pack();
        frame.setVisible(true);

    }

}

  • 1
    [mcve] please .. and add the exact fx version, there have been bug fixes around scaling recently – kleopatra Nov 22 '21 at 10:24
  • I have edited the question adding mre and exact java version – Silvio Barbieri Nov 22 '21 at 11:52
  • Construct and manipulate Swing GUI objects _only_ on the [event dispatch thread](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html), for [example](https://stackoverflow.com/a/31576647/230513). – trashgod Nov 22 '21 at 12:55
  • 1
    can reproduce it in fx8 - worksforme in fx11. btw (and in addition to the note from @trashgod): don't use internal api. This might be a xy-problem so you might reconsider solving the real problem somehow differently :) – kleopatra Nov 22 '21 at 13:15
  • I know I should use the event dispatch thread and should not use the internal api but the problem still stands: even if I use "SwingUtilities.invokeLater" and "new JFXPanel()". And, unfortunately I cannot update java version... – Silvio Barbieri Nov 22 '21 at 13:47
  • 1
    _And, unfortunately I cannot update java version..._ then you are out of luck with your approach, most probably - the recent (fx17+) changes were done deep inside, I doubt that they will be backported to fx8 - but you could try by reporting the issue. – kleopatra Nov 22 '21 at 15:24

0 Answers0