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

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top