Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Is there a layout for this?

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is there a layout for this?

    I am trying to put several components into a Panel with a BoxLayout set to BoxLayout.Y_AXIS, however, I am also attempting to get them to expand horizontally to fit the width. Essentially I want the same behavior as can be seen with border layout, except with out the limit of only having NORTH, CENTER, SOUTH Positions.
    JFrame frame = new JFrame("Test");
    JPanel panel = new JPanel();
    panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ));
    panel.add( new JButton("Button One"));
    panel.add( new JButton("Button Two"));
    frame.add( panel );
    frame.setSize( 300, 100 );
    frame.setVisible(true);

    This shows me two small buttons each against the left side, What I expect and want is two buttons one on top of the other each 300px wide, and I expect that if I resize the frame they would grow or shrink horizontally to fill the window. Is this possible? I have googled through all the Java Docs, and the Trail pages to no avail. Any suggestions would be appreciated...


  2. #2
    Member
    Join Date
    Sep 2011
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Is there a layout for this?

    Consider to use GridBagLayout, it is very flexible.

    java memory
    Last edited by namhm; December 4th, 2011 at 05:51 PM.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,298
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Is there a layout for this?

    Have you tried not giving the components a maximum size, as explained about halfway down the BoxLayout tutorial?

    How to Use BoxLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Layout Manager
    By mDennis10 in forum AWT / Java Swing
    Replies: 4
    Last Post: September 3rd, 2011, 10:27 PM
  2. Replies: 1
    Last Post: April 14th, 2011, 07:50 AM
  3. Grid bag layout inside grid bag layout
    By kiddkoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2011, 08:07 AM
  4. Layout manager
    By kurt-hardy in forum AWT / Java Swing
    Replies: 3
    Last Post: January 19th, 2011, 09:25 AM
  5. How do you layout these components centered
    By robertbob in forum AWT / Java Swing
    Replies: 2
    Last Post: May 24th, 2010, 11:52 PM