• Post Reply Bookmark Topic Watch Topic
  • New Topic

Box... dynamically adjust strut width  RSS feed

 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I'm using a Box (box) as my custom TreeRenderer; I'm using a Horizontal Strut with in this box to get some padding between a "label" and a "button"


Can you please suggest ideas on dynamically setting the width for the strut? Is there any other component that I could use for the same purpose? Basically I want all the Buttons in box aligned starting from some point; no matter the depth of the node

Thanks in advance
Ravi
 
Campbell Ritchie
Sheriff
Posts: 54089
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glue?
You have doubtless read the BoxLayout API page and the Java Tutorial page?
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well;

Glue works but I need a dynamic control of the space. All I want to do is to set the space (i.e gap) between components dynamically. I'm sure its possible isn't it? Am I something here...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a thought.

give 'width' some extra meat, then

this.add(Box.createHorizontalStrut(width-label.getPreferredSize().width));
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Micheal;
That Doesn't seem to work for me:

Basically my GUI looks like this:

Root < fixed strut> Button
------Child1 <fixed strut> Button
------------Child1.1 < fixed strut> Button

Whereas what I want to do:
Root < variable strut> Button
------Child1 < variable strut> Button
------------Child1.1 < variable strut> Button

Any Ideas???
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never Mind,

I actually separated my TreeCellRenderer and the Box; So basically I build the entire Box on the fly; so depending on the level of my node; I can set the glue. Thanks for all who responded.

Ravi
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!