aspose file tools*
The moose likes Applets and the fly likes JApplet and JPanel Stretching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "JApplet and JPanel Stretching" Watch "JApplet and JPanel Stretching" New topic
Author

JApplet and JPanel Stretching

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
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

Joined: Oct 27, 2005
Posts: 19722
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 823
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
I think this question would sit better on our Applets forum. Moving.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JApplet and JPanel Stretching