Re: A fixed size window in Java



Thomas Hawtin escribió:
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 you use validate instead of pack, then the window will not be resized. However, if the window is set to small, it'll be a mess.

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).

Adding the contents of your window to a scroll pane is worth doing. Even if the window is resized too small, it still wont look totally daft.

You might be better off setting a minimum size. Then if the contents are too big for the size you have set, a sufficient size will be used. From 1.5, the minimum size of a frame will tend to be honoured when the user resizes.

It can be useful to override a container's getXyzSize method. For instance, a minimum size that is below the preferred size can cause a mess. Or the preferred size might be silly small, and you want to add some internal padding on.

Tom Hawtin

I have tried that but now I have the same problem. The objets are not shown correctly. I have a Panel with some JLables layed out with GridBagLayout. When some labels are deleted and I want to be redisplayed that area using validate(), then the old labels are not removed (the actual JLabel are removed, but their graphics are not).

.



Relevant Pages

  • Re: Noob alert: trouble resizing canvas when app window is manually resized
    ... the ideal result would be the canvas (and ... its contents) is redrawn to fill the new size of window, ... want to redraw - create and pack it once at startup, ... global .c xpixels ypixels resizes ...
    (comp.lang.tcl)
  • Re: Noob alert: trouble resizing canvas when app window is manually resized
    ... the initial draw is do to the window mapping. ... proc main { ... proc doContents { ... # A bit of tbd logic could separate true resizes from other events. ...
    (comp.lang.tcl)
  • Re: A fixed size window in Java
    ... 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 you use validate instead of pack, then the window will not be resized. ... the minimum size of a frame will tend to be honoured when the user resizes. ... a minimum size that is below the preferred size can cause a mess. ...
    (comp.lang.java.programmer)
  • Re: Question about resizing a JPanel
    ... try calling the pack() method on the JFrame. ... This method resizes ... > the window to fit the contents. ...
    (comp.lang.java.gui)
  • Re: Minicom has only ansi or vt102
    ... >>You know much about Thunderbird? ... >which resizes the text if it is being wrapped locally; ... window *does* make it re-wrap. ... I have no filters set, ...
    (Fedora)