Java jframe scaling

Is it possible to create a JFrame and setResizeable(true) , but the values โ€‹โ€‹of x and y will scale by the same amount, that is, you cannot increase only x or y, but both at the same time, so that it remains proportional

+4
source share
1 answer

Although not ideal, you can add a ComponentListener to a JFrame by overriding specifically ComponentListener.componentResized - (since all you need is to simply extend the ComponentAdapter ).

Basic meaning:

  • Write the initial size of the JFrame (either with two integers or with a Dimension object).
  • When resizing a component, get the size of the current JFrame
  • Set the JFrame to a new size based on the old size with the new size (based on which there were always dimensions, height or width) increased more or less. You can play with this).
  • Burn new JFrame size
  • Rinse and repeat.

Hope this helps

+3
source

Source: https://habr.com/ru/post/1336237/


All Articles