Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Flowlayout question  RSS feed

 
N D Fisher
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my appplication I am using the 'FlowLayout.LEFT' layout to organise my buttons, but I'm trying to do something that I can't quite work out yet. This is how I want my buttons to look:



So basically the left three buttons will be sized automatically by the layout manager depending on the width of their content. But for the last button on the right I want it to fill the remainder of the container/window, regardless of the width of it's content. So if the user decides to increase the width of the window, the button will adjust it's size accordingly.

Can anyone shed any light on this please?

many thanks,

Nick.
[ November 19, 2008: Message edited by: N D Fisher ]
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you feel like torturing yourself you can look at GridBagLayout.

If you don't check out MigLayout or FormsLayout, both 3rd party code.
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by N D Fisher:
Hi,

In my appplication I am using the 'FlowLayout.LEFT' layout to organise my buttons, but I'm trying to do something that I can't quite work out yet. This is how I want my buttons to look:



So basically the left three buttons will be sized automatically by the layout manager depending on the width of their content. But for the last button on the right I want it to fill the remainder of the container/window, regardless of the width of it's content. So if the user decides to increase the width of the window, the button will adjust it's size accordingly.

Can anyone shed any light on this please?


Put the last button in CENTER of BorderLayout. Put the other
buttons in an intermediate panel in WEST/LEADING. I would be
tempted to use GridLayout for the intermediate panel so they
would all be the same size, but it sounds like you want to
use FlowLayout there.
 
N D Fisher
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the pointers, both.

Looks like I can sort this out with GridBagLayout.

Cheers,

Nick.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd strongly prefer Brian's solution. It's a lot easier, and you get to avoid GridBagLayout.
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by N D Fisher:
Many thanks for the pointers, both.

Looks like I can sort this out with GridBagLayout.



GridBagLayout can do (almost) anything, but it's almost always a pain in the tailbone. On the other hand, FlowLayout-within-BorderLayout should be pretty simple. Either way will work, as will others such as MigLayout or FormsLayout as mentioned by Mr. Prime.

[update: Sorry for the duplication, but he beat me by only a minute.]
[ November 19, 2008: Message edited by: Brian Cole ]
 
N D Fisher
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the comments. It does actually work fine with GridBag, and it's dead easy to implement. For the three buttons on the left I have set the 'weightx' component to 0.0, and for the right hand button it's set to 1.0. That way, any re-sizing of the window means the right button takes up all the extra space.

I just needed a pointer in the right direction.

Nick
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps it's easy with this simple layout, but GridBag becomes a pain in the behind when you need more complex layouts.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!