• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sizing windows dynamically  RSS feed

 
Richard Muller
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The window generated by the code below has its size set by the following line:

I determined the size by trial-and-error for a 1024x768 display. But I'd like to set the size dynamically. I tried packing the main window but that didn't work at all, presumably because the BorderLayout doesn't lend itself to that.
Will GridBagLayout give better results?

[ May 09, 2002: Message edited by: Richard Muller ]
[*** TAB characters removed ***]
[ May 10, 2002: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I'm understanding your question. If you want to size the window dynamically, couldn't you just set the size of the window (and any components you're concerned about) relative (as a ratio) to the size of the user's screen (which you've determined in your code)?
Let's move this conversation to the Swing / JFC / AWT forum...
 
Richard Muller
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dirk,
My question is: what's the easiest way to get a frame window automatically sized to contain it's components exactly.
The code I posted produces a window containg two components: (1) a scrolling pane containg a table; and (2) a pane containing three buttons arranged horiziontally.
But without my sizing statement (determined by trial and error):

the table wouldn't be displayed in full and abutted by the button pane. There would be a gap between them unless the user manually resized the frame window.
Regards,
Richard
[ May 10, 2002: Message edited by: Richard Muller ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The pack() method in java.awt.Window will do this for you. Of course, all the components inside this window need to have valid preferred sizes for this to work...

-Nate
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!