Question

I have a paint component where I draw some shapes but the problem my shapes exceed jPanel Size . because of that I search a solution of zoom jpanel. I don't know if this possible could someone help me I use net beans gui builder

Was it helpful?

Solution

If you want the shapes to size according to your JPanel, make use of the JPanel's getWidth() and getHeight() e.g.

int x = (int)(getWidth() * 0.1);
int y = (int)(getHeight() * 0.1);
int width = (int)(getWidth() * 0.8);
int height = (int)(getheight() * 0.8):
g.fillRect(x, y, width, height);

See a full running example here

You can see here how to customize initialization code for your JPanel in GUI Builder

OTHER TIPS

Add your JPanel to a JScrollPane and add the JScrollPane to the container you were originally adding your JPanel to. Make sure to setPreferredSize to a size large enough to see all of your drawings whenever you draw a new shape or however you are doing your graphics.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top