> > It opens a frame with the size 1100x100.
> You and I should read more closely. 1100x100 works correctly here. 100x100 doesn't.

It's expected behavior of java. First time 'releasing' window or other
native component you indirectly call Component.addNotify() that adds
native peer to component. During adding peer it can change size as it
wants (what it wants for Frame does depend on Window system and
particular on window manager if it is XWindow window system). The
general solution is to resize component after it is release. Further,
"to release" means do something that call addNotify(). From usual calls
these are pack() and setVisible(true) if called for the 1st time for
component. However remember that it is not safe to change size from any
other thread but EventProcessingThread as soon as component is released
such as AWT is not thread-safe. If you call pack() and then setSize()
*before* setVisible(true) or show() it is a good chance (maybe 100%)
that your setSize() will not clash with any event handler (such as a few
or no events are passed to component until it is visible), so this will
work almost always or even always (I cannot say 100%). Other way that I
am using and that must work in 100% is the following:

setVisible(true);
SwingUtilities.invokeLater()
        {
        new Runnable()
                {
                frame.setSize(100,100);
                }
        }

This includes utility from Swing that in fact must be available in AWT.
It allows you to execute some code in event processing thread. You can
also safely set initial size in window or component listener of some
ready event like WINDOW_OPENED or so.

Also be sure that your window manager ALLOWS so small Frames at all.
Otherwise, peer can prevent your setSize() from doing its work.

Hope this helps
Pavel

Reply via email to