File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Fixed Form Layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Fixed Form Layout" Watch "Fixed Form Layout" New topic
Author

Fixed Form Layout

James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi,

I have a 3 columns JDialog with display values and inputs.
(using GridBagLayout). I use JLabel for the display and
JTextField for the input.

The display value is from the database, as such the length
varies.

The problem I have now is that I end up having an inconsistence
form layout due to the JLabel eg: if it's long, the column
having the field would be wider.

Could someone please advise how I can achive a consistent
form layout.


Thanks in advance.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10343
    
    8

Since you mention JDialog and GridBagLayout I am inferring you add the components to a panel and then add the panel to the dialog. Have you considered overriding the getPreferredSize() of the panel?

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi Maneesh,

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.


Thanks.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10343
    
    8

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.
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi Maneesh,

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.


Thanks.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10343
    
    8

James Gordon wrote:If the column is resized, the other columns would end up being smaller right?

Not really. The other column would remain the same width as it is of fixed width. The overall result would be a dialog with a greater/smaller width depending on the label.

If the user is editing one field at one time, you can have the UI with two rows, one for the label and one for the field instead of two columns.
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi Maneesh,

Not really. The other column would remain the same width as it is of fixed width


The other columns would definitely get smaller because the size of the
panel is fixed.

If the panel width = 900px, size of each of the 3 columns = 900px / 3 = 300px

When one of the column grows (eg: 500px), it will definitely take up the spaces in other columns.

It's understood that the column has to grow to accomodate the long label.
But due to that, the layout might look slightly different based on how long the label is.

My objective is that if the column is 300px, it should remained 300px all the time.

One possible solution is to trim off the label but I don't think it's a simple
task as we've to consider the available spaces and label size (font, style, size).


Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fixed Form Layout