• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JApplet and JPanel Stretching

 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm drawing a series of shapes on a JPanel and then adding to JApplet Content Pane. Is there a way to draw shapes and then when you change the size of the JApplet to have the shapes resize in relation to the container they are in? Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20750
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside the paintComponent method (which you should override to do the painting), you can get the current width and height of the component. Use those to determine the size of your shapes.
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another example that might make it clearer what I'm trying to do.
If I create a 500x500 JApplet (setSize in JApplet) and draw a square near the boundaries of the JApplet. Is there a way to use the JApplet on a html page but have it display at a reduced size (say 100x100) whereby it looks like a minature version of? The reason for this is I want to have a small image on the page but putting the mouse over a div tag holding a reference to the same JApplet display opens except it's a larger version of. Similar to viewing a larger image of a product on an e-commerce site.
I'm using drawRect and drawLine to draw directly on the JPanel I'm using that gets added to the JApplet.

Any help would be much appreciated. Thanks.
 
Campbell Ritchie
Sheriff
Posts: 51349
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this question would sit better on our Applets forum. Moving.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic