10 Replies - 499 Views - Last Post: 01 July 2013 - 03:54 PM Rate Topic: -----

#1 musicalProgrammer  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 36
  • Joined: 13-November 12

Rock, Paper, Scissors game - GUI layout question

Posted 27 June 2013 - 09:15 AM

What is the best layout manager to use to make sure my components stay in a fixed position? I tried border, but that wasn't right. I'm thinking box, but I'm not sure.
Is This A Good Question/Topic? 0
  • +

Replies To: Rock, Paper, Scissors game - GUI layout question

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,362
  • Joined: 27-December 08

Re: Rock, Paper, Scissors game - GUI layout question

Posted 27 June 2013 - 09:17 AM

BorderLayout doesn't respect Components' preferred sizes, and the various regions expand to fill the space. I find a combination of BoxLayout, FlowLayout, GridLayout, and BorderLayout to be sufficient for most of what I do (which isn't very much GUI programming anymore). I'd play around with BoxLayout for now, but consider a mixture of the various layouts as necessary.
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7561
  • View blog
  • Posts: 12,680
  • Joined: 19-March 11

Re: Rock, Paper, Scissors game - GUI layout question

Posted 27 June 2013 - 09:19 AM

Your requirement is vague. "Stay in a fixed position" under what circumstances?
Was This Post Helpful? 0
  • +
  • -

#4 musicalProgrammer  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 36
  • Joined: 13-November 12

Re: Rock, Paper, Scissors game - GUI layout question

Posted 27 June 2013 - 09:33 AM

macosxnerd101 - How do I combine multiple layouts? I didn't know that could be done.

jon - If I resize my window manually, like I drag the corner of it make it larger or smaller, I don't want my buttons and labels to reorder themselves based on the current size of the window; I want them to stay put, no matter how big or small I make the window
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,362
  • Joined: 27-December 08

Re: Rock, Paper, Scissors game - GUI layout question

Posted 27 June 2013 - 10:34 AM

What you do is you use JPanels to achieve various subsections of the Layout, and add them to a main JPanel. For example, let's say you want a header. You would have a JPanel for the header, perhaps with a BoxLayout. The main JPanel might use BorderLayout. So you would add the headerPanel to mainPanel with the constraint BorderLayout.NORTH.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Rock, Paper, Scissors game - GUI layout question

Posted 27 June 2013 - 03:04 PM

View PostmusicalProgrammer, on 27 June 2013 - 12:33 PM, said:

If I resize my window manually, like I drag the corner of it make it larger or smaller, I don't want my buttons and labels to reorder themselves based on the current size of the window;

Use a GridLayout. The elements themselves will resize but they will stay in the originaql order :^:
Was This Post Helpful? 0
  • +
  • -

#7 musicalProgrammer  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 36
  • Joined: 13-November 12

Re: Rock, Paper, Scissors game - GUI layout question

Posted 27 June 2013 - 08:10 PM

Thanks guys. I'll see what I can do and check back with results.
Was This Post Helpful? 0
  • +
  • -

#8 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 415
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: Rock, Paper, Scissors game - GUI layout question

Posted 28 June 2013 - 12:15 AM

You could always use a GUI builder with absolute layout settings. The resulting GUI will look beautiful, but the resulting code will terrify the weak of heart. :P
Was This Post Helpful? 0
  • +
  • -

#9 schutzzz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 135
  • View blog
  • Posts: 338
  • Joined: 22-April 13

Re: Rock, Paper, Scissors game - GUI layout question

Posted 28 June 2013 - 01:14 PM

View PostFlukeshot, on 28 June 2013 - 07:15 AM, said:

You could always use a GUI builder with absolute layout settings. The resulting GUI will look beautiful, but the resulting code will terrify the weak of heart. :P/>


Ahhh I cringe just thinking about that.

musicalProgrammer, Also if you show us a picture of how you want the layout to look in paint or something we could give you a better idea of what you'll want to use.
Was This Post Helpful? 0
  • +
  • -

#10 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 822
  • View blog
  • Posts: 2,529
  • Joined: 29-July 11

Re: Rock, Paper, Scissors game - GUI layout question

Posted 28 June 2013 - 03:19 PM

If you are using Swing and don't like abusing yourself, GroupLayout done with WindowBuilder in Eclipse or the Netbeans gui editor. If you are using JavaFX, then GridPane with FXML.
Was This Post Helpful? 0
  • +
  • -

#11 legadema  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 15-December 10

Re: Rock, Paper, Scissors game - GUI layout question

Posted 01 July 2013 - 03:54 PM

i would recommend GridBagLayout its the more complete layout manager.. but if you think GridBagLayout is too complex go for JGoodies FormLayout!

This post has been edited by legadema: 01 July 2013 - 03:59 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1