Results 1 to 4 of 4
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Basic Swing Layout Question

    Hello,

    I am getting back into GUI programming after a year of doing command-line programs and am having trouble getting it all working again.

    I have a JPanel at the moment in my JFrame which I have set to have a (3,2) GridLayout. It looks like this: http://i.imgur.com/j1VjlNx.png?1

    I want it to look like this (This has been Photoshopped - well... GIMPed): http://i.imgur.com/07nJSQD.png

    i.e. I want the 6 areas to always be in the same place relative to each other but I want them all to be distinctly separate components so that I can change the statuses as I please. I want them to always remain in the middle-left of the panel - any expansion of the panel will be done by expanding the top and bottom of the panel.


    How do I set this up?

  2. #2
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: Basic Swing Layout Question

    Oooops, put this in Spring instead of Swing

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default Re: Basic Swing Layout Question

    Don't forget that you can nest layouts.

    I have a habit of over-using BoxLayouts, so to me this looks like a JPanel with a Y_AXIS BoxLayout that holds a glue, a second JPanel, and another glue.

    The glues will guarantee that the inner JPanel will stay in the middle of the screen.

    That second JPanel might have another Y_AXIS BoxLayout, and it holds 3 more JPanels. Those 3 JPanels might each have an X_AXIS BoxLayout and contain a JLabel for the label, a glue for spacing, and a JLabel to hold the value you want to be able to change.

    Like I said that's just my BoxLayout-centric approach, and there are a ton of different ways to lay things out. But the key will is to nest multiple JPanels to get the effect you want.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: Basic Swing Layout Question

    I will look into that layout, I haven't used it before, thank you :)

Similar Threads

  1. Which Java Swing Layout Do I Use?
    By OllyHal in forum AWT / Swing
    Replies: 2
    Last Post: 02-02-2012, 08:01 PM
  2. help with swing layout
    By TopNFalvors in forum New To Java
    Replies: 6
    Last Post: 04-08-2011, 05:22 PM
  3. Need Swing Layout Advice
    By Rocketz in forum New To Java
    Replies: 2
    Last Post: 03-08-2011, 12:46 AM
  4. Swing layout is done wrong
    By Onra in forum New To Java
    Replies: 5
    Last Post: 10-08-2010, 04:36 AM
  5. Add Swing Layout.jar
    By anilkumar_vist in forum New To Java
    Replies: 0
    Last Post: 10-02-2010, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •