0

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

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Nose Programmer
  • 115
  • 1
  • 2
  • 11

2 Answers2

0

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.

NESPowerGlove
  • 5,496
  • 17
  • 28
0

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

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720