aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes making resizable components? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "making resizable components?" Watch "making resizable components?" New topic
Author

making resizable components?

Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
I am making a Panel using BorderLayout. In the
center of the layout is a custom Canvas.
When the user resizes the window, I want the
canvas to get resized automatically according
to its preferred size in the BorderLayout.
What is the mechanism to achieve this? I notice
that buttons, etc. already do it automatically.
Thanks!


Sun Certified Programmer for the Java 2 Platform
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Are you setting bounds on the Canvus or is it set to the BorderLayout as well?
What do you mean by Custom?


GenRocket - Experts at Building Test Data
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
I don't know what you mean by setting bounds on the canvas. I am just setting an initial size for the canvas when it is created.
"custom Canvas" means I extended Canvas.
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
I have a solution, but it requires my panel to have something like this
addComponentListener(
new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
canvas.requestSetSize(canvas.getPreferredSize());
}
}
);
which is ugly, and besides, Buttons don't need this trick!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: making resizable components?