Yes, I'm just doing some basic swing stuffs;
adding components to a panel but I don't
see how overriding getPreferredSize would help.
I believe the behaviour is due to the layout
manager which try to re-arrange the display
dynamically each time.
If we would to look at other form designer eg: VB
when a label accomodate 20 pixel, it'll always
stay like that unless we resize the form. And when
the label is at coordinate (x,y) in our monitor, it
won't run from that location.
If you are using JOptionPane.showXXXDialog to popup the dialogs (which you should, as it is easier than creating your own dialogs), this method internally calls pack() which does take into account the preferred size.
To confess, I really do not understand what your problem is. If the label is of longer length, the column would obviously be resized accordingly. On the other hand, say you got labels ranging from 2 characters e.g. "ID" to multiple characters e.g. "Your display name", theoretically you can compute the widest character length (presuming your label text is static) and define the size accordingly. But, when you display only the label "ID", there would be lot of empty screen space, which is bad usability.
Joined: Aug 09, 2002
If the label is of longer length, the column would obviously be resized accordingly
If the column is resized, the other columns would end up being smaller right?
On the other hand, if the label is not long, the other columns would take up more spaces.
So, the layout depends on how long the label is; in which the text is from database.
From user point of view, I think it does matter if the layout for the same screen
changed for every record they are editing.