Skip to content
Advertisement

Need help to adjust a Zoom system in Graphics2D – Java

This is my 1st question here. I’m trying to build a White Page adjustable by zoom. It’s inside a JScrollPane, so the size of the JScrollPane’s ScrollBars are adjustable in the Dimension of that JPanel.

I want to adjust the size of those ScrollBars as the Size of the page (variables width and height in the code) + 2 borderSize, so the full size is equal the Page + margin of a borderSize around it. It works if zoom = 1.0.

If zoom < 1.0, the scroll bar is smaller than the Page and cut a piece of it. If zoom > 1 the Dimension size is way bigger than the page, leaving a huger border on its right and down corners, bigger than the borderSize.

How do I do this?

PS: I’m started learning java by myself, in the Quarantine last year, never had a teacher, just the internet, so any critics or suggestions, please, tell me.

Here’s the JPanel’s code:

JavaScript

Zoom(values from 0.1 to 2.0).

How can i improve this? Also, i have no idea how to update the JScrollPane’s scrollbars together with the zoom.Thanks for the help.

UPDATE: i’ve created a minimal reproducible exemple.

Advertisement

Answer

I’ve finally did it. Started by not using transformation for scaling it, but making a new draw with the size zoomed, adapting all sizes in the method setSizes(), and adjusting the Dimension by those sizes. (Just changed this class)

JavaScript

Thanks for all the help.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement