Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaSwing Layout Confusion/Difficullties
    primarykey
    data
    text
    <p>I'm still trying to figure out BorderLayout in JavaSwing, and it's really frustrating. </p> <p>I want to be able to split a pane into 3 contained sub-panels, but I'm not entirely sure how to contain it. </p> <p>Here is my class Game, which contains panels ControlPanel, StatePanel, and Board (really just an extension of JPanel). I want to split the panel into those three sections like this: <img src="https://i.imgur.com/ZzW67.png" alt="simple picture"></p> <p>Here is my code so far:</p> <pre><code>public class Game extends JPanel { private int panespace=2; private JPanel ControlPanel; private JPanel StatePanel; private Board board; public Game() { setLayout(new BorderLayout(panespace, panespace)); ControlPanel=new JPanel(); ControlPanel.setLayout(new BorderLayout(panespace, panespace)); ControlPanel.setBorder(new LineBorder(Color.red, 10)); ControlPanel.setSize(100,100); super.add(ControlPanel, BorderLayout.EAST); StatePanel=new JPanel(); StatePanel.setLayout(new BorderLayout(panespace, panespace)); StatePanel.setBorder(new LineBorder(Color.green, 10)); StatePanel.setSize(200, 200); super.add(StatePanel, BorderLayout.EAST); board = new Board(); board.setLayout(new BorderLayout(panespace, panespace)); board.setBorder(new LineBorder(Color.yellow, 10)); board.setSize(300, 300); super.add(board, BorderLayout.NORTH); setVisible(true); } } </code></pre> <p>Preferably, this would use BorderLayout, but I seem to be doing it incorrectly. I've tried reading the materials that Oracle provides, but they haven't been particularly helpful. At this point, I am at the point where I want to hard code values in, but I know that I should be able to split it to have each panel take up as much of the larger Game panel as possible.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload