• 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

JLabel words move?

 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty new at this.... I'm working on this project for school..... and starting by setting up the GUI it needs.

When I type in the odometer, cost and gallons fields, the label moves with the cursor...... what the heck??



I'd ultimately like the labels to be to the LEFT of the text areas.... and the text areas to be only one character high.... I can look that stuff up. I'm really mostly confused at the behavior of the labels when I type.

/Janeice
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the section from the How to Use Box Layout. It does some strange things because components can have different default horizontal alignments. So the simple answer is make sure the alignment is the same for all components.

Also, you should not be using a JTextArea for those fields. You should be using a JTextField. You will still get some wierd sizing of the components because of the way a BoxLayout handles sizing of components. The easy solution is to use:

textField.setMaximumSize( textField.getPreferredSize() );
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply and the link....

I was using the JTextField for those three components but it did (as you said) show up weird. I thought by changing it to JTextArea and setting the height parameter to "1" it would show up one character high.... it didn't and I didn't get around to changing it back before I realized the labels were moving and freaked out.
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used the textField.setMaximumSize as suggested.

Worked really well for the sizing and also for the moving JLabels.... my original thought was that it would work for the sizing but not the justification.....

Not like I'm complaining, but WHY did it work for both?

/Janeice/
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know for sure why it does what it does.

As I suggested in my first reply did you check the alignment of each of the components to see what the difference might be?
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The site says:

By default, most components have center X and Y alignment. However, buttons, combo boxes, labels, and menu items have a different default X alignment value: LEFT_ALIGNMENT.



I think it's weird that when I set the maximum size it stopped the labels from moving. Everything showed up left justified when I made that change.

--Janeice
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic