0

I am making a simple maze program where the user can create walls, paths, the start and the finish, click solve and the maze will be solved. To do this I have a java JFrame with the size 640x480. On the left side of the JFrame I have a JPanel with top left coordinates of 0,0 and the size is 480x480. This is the area where the maze will be drawn and where the user can specify the walls and paths. The problem I have is when I start adding buttons and radio buttons on the right side of the screen. Every layout I use (such as boxlayout, springlayout, flowlayout or grid layout) does not seem to do what I would like. I would like to have the JPanel stay were it is (on the very right with the size 480x480) and have the buttons arranged top-down starting at 480 (because this is where the JPanel ends). What I am thinking I need is ton specify where the layout starts and not to automatically arrange the JPanel. Is there any way that I can do this? Or do I just need to have a null layout?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jake Runzer
  • 957
  • 3
  • 17
  • 35
  • for better help sooner post an [SSCCE](http://sscce.org/), – mKorbel Oct 03 '12 at 23:17
  • The textual description of the GUI makes no sense to me. Can you draw it in ASCII art or a paint app.? – Andrew Thompson Oct 04 '12 at 02:32
  • Here is a gyazo of what I what the final product to look like, http://gyazo.com/2ca907828264729f3e7b1a948774433e. The Jpanel is on the right at a specific size and the buttons are arranged top-down on left. – Jake Runzer Oct 04 '12 at 02:58

2 Answers2

1

I would use a BorderLayout; put your 480 square panel in the CENTER, and set its min, max, and preferred size to 480. (There is a question whether this is a good idea, but you say you want this specific dimension.)

Put another JPanel in the SOUTH, and have it automatically arrange your buttons however you want. There are layouts for arranging them left-to-right, one row or two, etc.

You can then do things specific to the creation of walls and doors in the center JPanel, and the user can resize the window and the layout manager for the buttons will do what you specify for that.

arcy
  • 12,845
  • 12
  • 58
  • 103
1

take a look at this answer of mine:

Positioning of components (how to place a few buttons center screen same size)

Jframe not the right size when its executed, any reason why?

What you want to do is have a JPanel 480x480 over a set of radio button. Just use a BoxLayout with PAGE_AXIS and follow my guide in the link.

Community
  • 1
  • 1
Gianmarco
  • 2,536
  • 25
  • 57