Linux: IJ scaling on hiDPI screens

imagej1
hidpi
imagej

#1

@Wayne,

The recent Prefs.setGUIScale() option makes ImageJ finally usable on Linux on hiDPI displays (where to my knowledge AWT components never scale no matter which JRE you use). Thanks for that.

But there were still many widgets and components that needed to be patched: I tried to do it here with PR#73, which applies the scaling to almost all the remaining dialogs and widgets, including the Histogram & Plot Windows and the Threshold widget (the biggest annoyances for me).

Also, note that in Linux, Swing components can scale but only under certain circumstances: E.g., With Ubuntu and Java 8 only if you use the GTK L&F. Thus, it is not clear to me what to do on those cases, as there is the risk of over-scaling: It is happening already with the built-in IJ Command Finder: Fonts will appear exaggerated if you set Prefs.setGUIScale() to 2 under the GTK+ L&F). So I tried to put in place some basic detection of pre-scaling by the UIManager, but it won’t be perfect.
Anyway, using a 4K screen at full resolution is so liberating that I’m fine with whatever happens with the few Swing components IJ1 uses. Now the only thing missing is antialiasing text in IJ’s GUI!

I attached a compiled ij.jar to the PR in case some of you wants to try it.
(mentioning @krs5, @gabriel, @albertcardona, as per the initial mailing list discussion).


#2

@tferr I wonder if you have tried OpenJDK 11 on Linux which should scale the different components.

At least on Windows (tried on a 3000*2000 resolution) it scales components (including AWT) when using OpenJDK11. Exception are the CheckBoxes.

However I haven’t tried it on Linux yet.


#3

Hi @Bio7,
Tried only with openjdk11 on ubuntu 18.04/18.10. And things don’t change. Here is a snapshot of some AWT components: only the dialogs on the right side that are aware of @Wayne Prefs setting scale:


Also, it is very disappointing to see that font antialiasing for AWT is still not in place. At this point, I think we just have to live with it as is :frowning:


#4

I have started ImageJ from the command line to get my required results which I had to find out painfully for my application - along with other Java>=9 changes).

However I start ImageJ with (scale can vary with this option):

java -Dsun.java2d.uiScale=2.0 -Xms2048m -Xmx4096m -cp ij.jar ij.ImageJ

And you are absolutely right. The fonts are horrible. When I port ImageJ to Swing the fonts look nice but Swing component ports are hard to maintain (with all side effects caused by object casts at runtime).


#5

That is actually not true for Java 9 and newer:

Since Java 9 the GDK_SCALE environment variable is used to scale Swing applications accordingly.

IJ not scaled (using openjdk8 on arch linux with plasma):

IJ scaled (using openjdk10 on arch linux with plasma):

I updated the screenshots: Both images in the background are halfwidth full height (minus the task bar) of my 4k screen


#6

@hanslovsky What about checkboxes. On Windows there are still tiny (JDK bug?). E.g. the set measurements dialog.


#7

That looks fine to me (screenshot for scaled ij only):

Again, half width, half height of my 4k screen


#8

Here are my screenshots (3000x2000):

Screenshot scale 2.0 with bad MenuItem distance:

Screenshot, default scale with tiny CheckBoxes:


#9

What I just noticed on my screenshots: The check marks are actually very tiny and not even inside the boxes. I thought that the shade of the box indicated selection and thus thought that the check boxes were fine. :smile: :smile: But no, similar issue on (my) Linux, then.


#10

For completeness, more of the dialogs that @tferr used in his initial example (scaled):


#11

@hanslovsky, @Bio7, you are both right. Yes. I confirm the scaling occurs if you specify the -Dsun.java2d.uiScale flag. I had tried it in the past but only on java 8 and somehow forgotten about it. Thanks for the correction. this is good news. However you still have that exaggerated scaling I mentioned above on swing components if you use it in conjunction with the GTK look and feel, e.g., /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Dsun.java2d.uiScale=2 swing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -jar ij.jar, so the entire thing is a bit clunky.
Also, I noticed that @Wayne’s trick is somewhat smarter, because it does not scale margins of components indiscriminatingly and on imagecanvas, text render much better due to antialising. Here is a snapshot: left column: windows scaled by -Dsun.java2d.uiScale=2, right column windows using wayne’s font scaling trick by the same factor:

(and as a bonus, the tickmarks on checkboxes seem to scale properly :slight_smile: )


#12

These changes are in the ImageJ 1.52m26 daily build. The commit is at https://github.com/imagej/imagej1/commit/99b0ee659c025a8882bb531c398b6a8a0b772ca1


#13

With this changes many dialogs now are working on Windows, too.

But the Checkboxes on Windows do not scale even with the argument -Dsun.java2d.uiScale=2 which can also be applied on non highdpi screens to scale components (see screenshots below).

Non HighDpi:
grafik

HighDpi:
grafik

The ColorThreshold dialog is still tiny but can be scaled, too with the new command GUI.scale(this);

Plugins are only scaled if they use the default ImageJ API.


#14

This looks like a Windows Java bug. Checkboxes do scale on macOS and Linux.

The Color Threshold dialog is scaled in the latest daily build (1.52m30).


#15

Hello @Wayne I created an overview screenshot with some more HighDPI issues.

Most of them related to a too small frame and font size. Also selections look tiny. The desktop screenshot (original size) shows the default ImageJ download which is currently bundled with 1.8.0_112 and your custom scaling adaptions on Windows 10 laptop (3000X2000):

If you open ImageJ (fresh install) the application is scaled by Windows which is not true high dpi unfortunately (a bit blurry - however everything is scaled).

On MacOSX everything looks simply fine (best scaling of all OS’s)


#16

Hi Marcel,

Just a note: I’m surprised the “Batch Process” dialog does not scale. It seems to scale well on Linux. Also to me, the smaller font size on ResultTables, Editor and Text Windows is not really a problem: By clicking a couple of times on Font>Make Text Larger, text renders at a suitable size, and it will be remembered across restarts. The only one that does not seem to be respected is the font on plots (Axes titles and labels), that although it seems to be stored properly on the IJ_Prefs file, it seems to be ignored by the PlotWindow.


#17

@tferr

Also to me, the smaller font size on ResultTables, Editor and Text Windows is not really a problem: By clicking a couple of times on Font>Make Text Larger, text renders at a suitable size, and it will be remembered across restarts

Yes I’m aware of the font settings. However if the application is scaled (ImageJ scaling) it would be nice if the font and window size would be scaled, too.

Another problem which I mentioned earlier are of course external plugins not using the GenericDialog class, etc. (ImageJ API)


#18

It would indeed. It is a bit clunky right now having to do it for every text window and applying it to Window dimensions makes sense.

I really don’t think there is a simple way around it rather than dive in one by one and adjust it. I guess there shouldn’t be many? Let’s make a list here so that as soon as someone finds the time he/she can chip in:

  • ChannelArranger
  • ControlPanel
  • ColorPicker
  • FunctionFinder
  • Scaled fonts in text windows and PlotWindows by default
  • Scaled dimensions for non-image windows by default

In addition to it there are still ImageCanvas components that would be nice to scale:

  • Image subtitle
  • ROI handlers
  • “Arrows”, “R”, “F” and “SetLimits” handlers in PlotWindows

Anything else?


#19

Just a follow-up.

If I convert the ImageJ toolbar context menus to Swing everything is scaled correctly with the Java scaling and the text on Linux is fine, too.

In addition the JCheckBoxes and the JScrollBar (AWT Scrollbar looks oversized in height) scale correctly on HighDPI.

So it seems that some AWT components do not scale correctly on Windows.


#20

The latest daily build (1.52m37) supports scaling of the Color Picker, the Function Finder and image subtitles. Modify “GUI scale (0.5-3.0)” in the Edit>Options>Appearance dialog to set the scale.