• Post Reply Bookmark Topic Watch Topic
  • New Topic

BoxLayout: unsihtly vertical gap betw components?

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all.
I've tried this BoxLayout with PAGE_AXIS and X_AXIS alignment, it works, but there is this big gap between the components vertically. The components are self-defined and consists a pair of JLabel and JTextArea.
How do I pack the components tighter vertically i.e. along the Y-Axis ?
TIA :-)
Here is the stub code for BoxLayout:

And here is the helper-class for the JLabel and JTextArea pair, called by the aforementioned code to insert the pair into the BoxLayout.
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've also tried using "struts", but they have no effect...
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've also tried following :

None of which works, can someone please help out, if you can?
TIA :-)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add a "glue" component to put at the bottom to fill up the extra space, or it is distributed among the other components. Struts make space, they can't shrink it.
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I did add the verticalGlue, like this:

But the unsightly vertical gap remains the same.
Thanks so much for taking time to look into my problem... :-)
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I changed the code to avoid using the customized sub-class LabeledTeaxtField and it seems to work

But I always need a pair : JLabel + JTextArea
That's why I'm using the customized helper-class LabeledTeaxtField , but it stops working when I use it.
This is *annoying* !
TIA :-)
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might explain it.
I put a border around the JLabel + JTextArea pair defined by the custom helper class LabeledTextField, and it seems LabeledTextField forces a rigid area around it.
Is this because LabeledTextField extends JPanel ???
If so how do I get rid of the rigid area enforced by JPanel ???

TIA :-)
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done!
Thanks for helping out.
web page
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!