permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes GUI Example (HFJ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI Example (HFJ)" Watch "GUI Example (HFJ)" New topic
Author

GUI Example (HFJ)

Mikpo Siru
Ranch Hand

Joined: Apr 09, 2009
Posts: 54
Hi,

The code from page 371 makes a JFrame, inside of which is a button and a custom widget. The custom widget fills the background black, and also draws an oval whose colour changes randomly when the button is pressed.



What I don't understand is how the custom widgets' width and height attributes are being updated with the JFrames size - even as I resize the frame, becuase I haven't assigned anything to the attributes in code.

Thanks

MCU
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2156
    
    7
Because you added your panel to the CENTER of a BorderLayout. The panel is automatically resized to occupy all the spaces available to the panel.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: GUI Example (HFJ)
 
Similar Threads
GUI Problem
Head First Java Question - GUI program TwoButtons
problem with simple swing GUI program
why does this code fail?
need help with my code