• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternative to Null Layout

Avi Abrami
Ranch Hand
Posts: 1141
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My IDE has a visual editor for creating Swing applications.
The created application windows have no layout manager and use method
"setBounds()" for placing Swing components on the application window.
I have built an application that uses JInternalFrame.
Each JInternalFrame is a separate and different "screen" for the user to
interact with.
There are around 2,000 screens in the application and new screens are
constantly being added as well as existing screens being modified.
As a result, the top-level container - a JFrame - is a fixed size and is
not resizable.
I have now been asked to increase the size of the JFrame while maintaining
the proportions of the screens.
Rather than manually editing the invocations of "setBounds()" on all the
screens, can someone suggest an alternative way to achieve this?
Also, is there a way to achive this such that if, in future, the JFrame
will again be resized, the screesn will automatically adjust?

Thak you,
Piet Souris
Posts: 1402
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Avi,

Ai, that doesn't sound nice. You know, if you don't use a LayoutManager,
then you take full responsibility of placing (and depending on the component)
sizing your components, as well as dealing with resizing.

Tell me: these JInternalFrame's, of which you have abount 2.000,
do they all fully occupy the contentpane of the fixed-size main frame?

If they don't, then one could ask himself why bother in keeping the
proportions (relative to your mainpanel?).

But all is not lost. The "easiest" way I can think of is to first determine
the size of your new main frame. You know the size of the current
frame, and from this you can determine the "increase factor" for
width and size.

Then iterate over all your screens. You know their current sizes, you know
the size of your main panel, and from that you can determine
the "increase factor" for your screen.

Then, given such a screen, get a list of all the children. There is a method
for this (getComponents), and, depending on the type of component,
and given the "increase factor", you can adjust the bounds.
Mind you, if the component is a JButton, you might not need any
adjustment at all. And for most of the components, just adjusting the (x,y)
would do, no need to adjust their full size. For instance,
if you have a JLabel with some text, you do not need to increase its

Well, easier said than done, but at least you have a program
in which the layout is based solely on the size of the main frame,
easy for future changes.

As said, this looks easiest to me. Rethinking of the whole system
is also an option, but will no doubt take much longer.

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic