• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

making resizable components?

 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you setting bounds on the Canvus or is it set to the BorderLayout as well?
What do you mean by Custom?
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic