Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Flowlayout question

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 22579
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 975
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22579
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 975
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22579
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic