• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

UI Scaling Question

 
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application which I would like to scale the UI of. Initially, this was just something that I wanted to offer for Linux users (as dynamic scaling seems to simply not work any more in Ubuntu), but I realized if I was going to code it, I might as well flesh it out a bit more.

I have found some VM arguments across the web that folks have told me to set, but none of those are changing the scaling when I actually run the program (and I've tried in both macOs and Ubuntu).

Ideally, I would like to have an options menu set up where you can enter in a scaling value. I realize that it might require a restart of the program for this to take effect, but I am still having trouble getting this to work.

Also, given that I use jlink to create a binary for my distribution, is there a good way to dynamically decide what VM arguments to hand in? I wish I had more code to share here, as that's typically a starting point, but I feel like this might be something which is set up entirely outside the source of my project.

Any help much appreciated.
 
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Java version are you using? Can you show us the command you are using to run your application?
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh jeez, I should have included that.

It’s running on Java 17, and I build executable binaries by building then using jlink to package everything up. So if I’m starting it in Windows, I just do so by opening the app’s exe file.
 
Stephan van Hulst
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you give us the jlink command you're using?
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh, sure thing! I am hoping that I can set this up somewhere other than the actual jlink step, as I would really like to have this be a scalable feature, but if I need to, I can make due with a process that produces a number of differently scaled executables (for Linux in particular). I didn't bother including everything on the module path below, but if it would be helpful, I can expand that to show everything.

 
Stephan van Hulst
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, here's what I figured out so far:

Apparently you can set the DPI setting on your application by passing the sun.java2d.uiScale option to the JVM. To do this for jlink executable, you can use the add-options plugin.

If you're using Maven, you can integrate all of this into your build by using the maven-jlink-plugin.

I realize this will build the setting into your executable and you want to change it at runtime, but please first try it out to see if it works so we can continue working on the problem from there.
 
Saloon Keeper
Posts: 28765
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wasn't quite sure what "scaling the UI" meant, but I suppose you mean that the on-screen image of the app in question should be resizeable AND that you want the UI elements (fonts, buttons, and so forth) to resize along with the app window(s).

That level of automatic scaling is generally done by the GUI desktop, which could be any one of a number of programs in Linux (I use Cinnamon, which is a spin-off of Gnome). So if and how you could zoom an application's window (or the whole screen) would depend on what desktop you're using. Microsoft Windows has its own mechanisms, but it only has one available desktop manager. Generally desktop scaling is done by pixel magnification, so zooming may give fuzzy results.

Resizing UI elements within the application is done by the Java graphics libraries and they are not dependent on what OS you are using. You'd have to do that in your own code.
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Okay, here's what I figured out so far:
use the add-options plugin.



Alright, this is progress, thank you! Obviously this builds it into the linked/packaged file though. Do you know if there is any way to modify the value on startup before any of the graphics for my application are initialized? That would allow this to be set in the options menu of my program/be respected on program restart.

EDIT: I have tried adding the below to the program's main() function, but that does not seem to work.

 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Update on this one.

UI Scaling seems to simply not work on macOS in particular. The code posted above does work in Linux, which was my biggest issue. I am still trying to get this to work in macOS simply to give users an additional feature, though.

In Windows and Linux, adding this in the beginning of the main method will change the scaling appropriately, pulling from my program's options:



However this is ignored in macOS. It was suggested elsewhere online that I try each of the below, but neither of these work either:



and conversely



After doing some digging, I found that macOS handles its own scaling, which actually seems to cancel out any changes that I make to the scaling. Is there any way to turn off the macOS scaling through VM options? If it's not possible, this option might simply not be available for mac users, but I would like to provide it for everyone.

Also, thank you for the help so far, it steered me in the direction I needed! ^^
 
Stephan van Hulst
Bartender
Posts: 15743
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, any information I can find on this sort of implies that macOS does whatever it wants, and the only way for you to deal with this is to figure out what the DPI settings on the host system are and then perform programmatic scaling of your UI. This doesn't really sound like it's worth it to me.

Can you write a small test-application in JavaFX to see if you can easily scale it on macOS? If it does, you might consider rewriting your UI in JavaFX. I'd like to help you with this one, but my house is Apple-free.
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well shoot, I had found some of the same things, but had hoped that there was some simple workaround that I might be able to implement for macs. The most I was able to do is make the whole program look blurry when the OS auto resizes it.

Anyhow, the program I am implementing this for is fairly mature at this point, with extensive UIs. Reworking that all into Jfx is unfortunately a way bigger task that I could take on at the moment. It would be a neat feature, but Mac users are only about 1/5 of my relatively small user base ad it stands.

Thank you for the help, though! It’ll be a nice feature for my Windows users and a godsend for anyone with a modern display on Linux!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic