• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Fixed Form Layout

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
James Gordon
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic