Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zoom in Java Swing application

I am looking for ways to zoom in a Java Swing application. That means that I would like to resize all components in a given JPanel by a given factor as if I would take an screenshot of the UI and just applied an "Image scale" operation. The font size as well as the size of checkboxes, textboxes, cursors etc. has to be adjusted. It is possible to scale a component by applying transforms to a graphics object:

 protected Graphics getComponentGraphics(Graphics g) {
  Graphics2D g2d=(Graphics2D)g;

  g2d.scale(2, 2);

  return super.getComponentGraphics(g2d);
 }

That works as long as you don't care about self-updating components. If you have a textbox in your application this approach ceases to work since the textbox updates itself every second to show the (blinking) cursor. And since it doesn't use the modified graphics object this time the component appears at the old location. Is there a possibility to change a components graphics object permanently? There is also a problem with the mouse click event handlers. The other possibility would be to resize all child components of the JPanel (setPreferredSize) to a new size. That doesn't work for checkboxes since the displayed picture of the checkbox doesn't change its size. I also thought of programming my own layout manager but I don't think that this will work since layout managers only change the position (and size) of objects but are not able to zoom into checkboxes (see previous paragraph). Or am I wrong with this hypothesis? Do you have any ideas how one could achieve a zoomable Swing GUI without programming custom components? I looked for rotatable user interfaces because the problem seems familiar but I also didn't find any satisfying solution to this problem.

Thanks for your help, Chris

like image 779
Shirky Avatar asked May 31 '10 15:05

Shirky


People also ask

How do you zoom in in Java?

Press the ''ESC'' key. Select Options. Slide the FOV bar to the left to zoom in or to the right to zoom out.

Is Java Swing still used in 2020?

Swing and AWT will continue to be supported on Java SE 8 through at least March 2025, and on Java SE 11 (18.9 LTS) through at least September 2026.

Is swing still used in Java 2021?

Absolutely yes. Legacy swing applicationsswing applicationsThe Swing Application Framework (JSR 296) is a Java specification for a simple application framework for Swing applications, with a graphical user interface (GUI) in computer software. It defines infrastructure common to most desktop applications, making Swing applications easier to create.https://en.wikipedia.org › Swing_Application_FrameworkSwing Application Framework - Wikipedia are still supported and enhanced.

How do I change the size of my Java Swing in Windows?

Using setSize() you can give the size of frame you want but if you use pack() , it will automatically change the size of the frames according to the size of components in it.


Video Answer


1 Answers

You could give a try to the JXLayer library.

There are several tools in it, which could help you to make a zoom. Check the examples shown here. I would recommend you to read more about the TransformUI, from this library. From the example, it seems like it could help solving your problem.

like image 104
Gnoupi Avatar answered Oct 25 '22 11:10

Gnoupi