Bug 150960 - Use platform look and feel (plaf) and scaling for Java windows
Summary: Use platform look and feel (plaf) and scaling for Java windows
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: difficultyInteresting, easyHack, skillCpp
Depends on:
Blocks: HiDPI
  Show dependency treegraph
 
Reported: 2022-09-14 16:11 UTC by Hossein
Modified: 2023-02-17 09:00 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
BeanShell window with small fonts and gui elements (147.08 KB, image/png)
2022-09-14 16:11 UTC, Hossein
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2022-09-14 16:11:07 UTC
Created attachment 182446 [details]
BeanShell window with small fonts and gui elements

I was working with the just released NetBeans 15. I use a HiDPI display with a 2x scaling. When opening the program, it said:

    "Detected 2x HiDPI scaling in Xft.dpi setting; setting GDK_SCALE=2"

Then it loads the IDE with GTK look and feel (plaf). It's nice and usable on a HiDPI display. The same trick for BeanShell editor can make it look better.

IntelliJ IDEA also supports HiDPI screens.

HiDPI article on IntelliJ docs:
https://intellij-support.jetbrains.com/hc/en-us/articles/360007994999-HiDPI-configuration
Comment 1 Hossein 2023-02-10 09:33:16 UTC
Using the below parameter, one can change the scaling for a Java application via JRE startup parameters:

 java -Dsun.java2d.uiScale=2.0 App

Java 9 might be required for this option.
https://openjdk.org/jeps/263

I have tested the above parameter by adding it to the LibreOffice settings. I went to "Tools > Options > Advanced > Parameters", then added "-Dsun.java2d.uiScale=2.0" as the parameter. After that, I opened the "Macros > Organize Macros > BeanShell", selected a macro from the tree, then clicked "Edit". In this way, the window was shown with 2x scaling.

To fix the issue and achieve automatic scaling, one can detect the scaling via GDK_SCALE or other means in other platforms, and then apply the scaling factor using the uiScale parameter, which also accepts fractional values for the scaling.

On the other hand, it would be possible to implement the scaling inside our application too. For example, IntelliJ IDEA has internal scaling capabilities:
https://youtrack.jetbrains.com/issue/JBR-3757
Increasing the font size would be part of this approach.
Comment 2 Hossein 2023-02-10 10:28:45 UTC
For the look and feel, it is possible to use Java startup options.

For GTK:
-Dawt.useSystemAAFontSettings=on
-Dswing.aatext=true
-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
-Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel

It is also possible to change the look and feel after the startup:
https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

These are some of the usable plafs:

com.sun.java.swing.plaf.gtk.GTKLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.mac.MacLookAndFeel
Comment 3 Hossein 2023-02-16 15:00:00 UTC
Let's turn this into an EasyHack. The Java options are now set manually using the "Tools > Options > Advanced > Parameters" dialog.

As a starting point, the relevant UI and code for setting parameters manually is inside these files:
 cui/uiconfig/ui/javastartparametersdialog.ui
 cui/source/options/optjava.cxx

The solution should be able to set the Java parameters automatically depending on the platform specific options, including the scaling factor.
Comment 4 Stephan Bergmann 2023-02-16 16:22:07 UTC
(The place where any general JNI JavaVMInitArgs options are set programmatically is initVMConfiguration in stoc/source/javavm/javavm.cxx.)