Note that there are some explanatory texts on larger screens.

plurals
  1. POBoxLayout misunderstanding strut
    primarykey
    data
    text
    <p>I'm prgramming a simple input diagram in Swing. I use boxLayout to create a simple GUI of user input. Problem is that creating a horizontal strut between the JPanel of all the labels and the JPanel of the JTextFields causes the whole panel to shift downwards (weird) this is the whole panel:</p> <pre><code>private JPanel secondCard() { //main panel. set the boxlayout secondCard = new JPanel(); secondCard.setLayout(new BoxLayout(secondCard,BoxLayout.Y_AXIS)); // create vertical strut for looks secondCard.add(Box.createVerticalStrut(20)); // create title. center it. JLabel title = new JLabel("Configure main network parameters "); title.setAlignmentX(CENTER_ALIGNMENT); secondCard.add(title); // create vertical strut for looks secondCard.add(Box.createVerticalStrut(20)); // create panel for the description labels JPanel labelPanel = new JPanel(); labelPanel.setLayout(new BoxLayout(labelPanel,BoxLayout.Y_AXIS)); labelPanel.setAlignmentX(LEFT_ALIGNMENT); JLabel inPut =new JLabel("number of inputs"); inPut.setAlignmentX(LEFT_ALIGNMENT); labelPanel.add(inPut); inPut =new JLabel("number of outputs"); inPut.setAlignmentX(LEFT_ALIGNMENT); labelPanel.add(inPut); inPut =new JLabel("number of layers"); inPut.setAlignmentX(LEFT_ALIGNMENT); labelPanel.add(inPut); JPanel textFieldPanel = new JPanel(); textFieldPanel.setLayout(new BoxLayout(textFieldPanel,BoxLayout.Y_AXIS)); textFieldPanel.setAlignmentX(LEFT_ALIGNMENT); JTextField inputTextField = new JTextField(); inputTextField.setAlignmentX(LEFT_ALIGNMENT); textFieldPanel.add(inputTextField); inputTextField.setMinimumSize(new Dimension(0,0)); inputTextField = new JTextField(); inputTextField.setAlignmentX(LEFT_ALIGNMENT); textFieldPanel.add(inputTextField); inputTextField.setMinimumSize(new Dimension(0,0)); inputTextField = new JTextField(); inputTextField.setAlignmentX(LEFT_ALIGNMENT); textFieldPanel.add(inputTextField); inputTextField.setMinimumSize(new Dimension(0,0)); textFieldPanel.setMaximumSize(new Dimension(50, labelPanel.getMaximumSize().height)); JPanel inputPanel = new JPanel(); inputPanel.setLayout(new BoxLayout(inputPanel,BoxLayout.X_AXIS)); inputPanel.setAlignmentX(CENTER_ALIGNMENT); inputPanel.add(labelPanel); //this is the problem strut!! it causes inputPanel to shift downwards inputPanel.add(Box.createHorizontalStrut(20)); inputPanel.add(textFieldPanel); secondCard.add(inputPanel); return secondCard; } </code></pre> <p>without the strut it looks like: <img src="https://i.stack.imgur.com/fsuDE.jpg" alt="enter image description here"></p> <p>With strut it looks like (I know I suck at picture editing):</p> <p><img src="https://i.stack.imgur.com/DRyR5.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    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.
    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