Re: A fixed size window in Java



On Sat, 2006-04-29 at 15:07 +0000, C. wrote:
Hello. I am writing a Java application with Swing and I need a Window
with a fixed size, because every time I call "pack" because some
components of that window change, the Window is resized to fit exactly
that components.

If I use Frame.setPreferredSize(...) then the components are not shown
correctly when I call pack (some ones are displayed over other ones and
so on).

What can I do to implement a fixed size window?

Thank-you very much.


It might be worth your while to look into JLayeredPane. Instead of a
LayoutManager, it lets you stack things on top of another with specific
Bounds relative to the container. This gives you some control that
regular layout managers don't.

You will still have the same problems if you pack() a container, but if
the LayeredPane's bounds and size getters return the right values, it
will do the right thing.

Lot of work, but any kind of custom layout always is, and LayeredPane is
not that bad...

.



Relevant Pages

  • Re: custom component painting
    ... first time that a container should be laid out is as part of pack(). ... The right thing is to have the component bounds set during layout. ... you invoke pack(), the first layout is done by pack. ...
    (comp.lang.java.gui)
  • OWA Issues
    ... I uninstalled and reinstalled Plus Pack ... on the server and then on the client and that worked. ... We are running OWA over SSL. ... the message composition window does ...
    (microsoft.public.exchange2000.clients)
  • is EVENT_BUFFER_SIZEs default too small? [LONG]
    ... more events than Tk can handle, the oldest events are lost. ... press and also a window raise event. ... set mainframe ... pack $b -side top ...
    (comp.lang.tcl)
  • Re: A JLabels Size
    ... When I create a JLabel and place it into a JPanel/JDialog/some other ... container it is in is either packed or its size is set. ... a side effect of pack() validating the Window. ...
    (comp.lang.java.gui)
  • Re: window size problem
    ... will pack the outer frame around the preferred size of its outermost child. ... 15 character wide window header. ... > layout.putConstraint(SpringLayout.NORTH, headerPanel, ...
    (comp.lang.java.gui)