Note that there are some explanatory texts on larger screens.

plurals
  1. POGridBagLayout panels alignment
    primarykey
    data
    text
    <p>I have a little issue with the GridBag Layout Manager. I am trying to display 9 panels like this:</p> <p><img src="https://i.stack.imgur.com/gRviM.png" alt="Ideal Layout - Illustrated"></p> <p>To do so, I separated the Grid like this:</p> <p><img src="https://i.stack.imgur.com/DVf7v.png" alt="Work In Progress - Illustrated"></p> <p>For the panels 1 to 7 there is no problem, they show up just as I want. But the issue starts with the panels <code>S8</code> and <code>S9</code>. As you can see, the <code>S8</code> and <code>S9</code> takes up half the frame, but I can't make it display like this. The <code>S8</code> ends at the start of <code>S4</code>, and the <code>S9</code> begins at the end of <code>S4</code>, I cannot handle the half space.</p> <p>Only way I figured out is to put the <code>S8</code> and <code>S9</code> panel in another panel which takes all the frame width - but surely there must be a proper way to display these two panels without putting them in another panel!</p> <p>Here is the code:</p> <pre><code>workzone.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; c.weightx = 0.5; c.weighty = 0.5; c.insets = new Insets(0,0,0,0); //S1 c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.gridheight = 2; workzone.add(S1, c); //S2 c.gridx = 2; c.gridy = 0; c.gridwidth = 2; c.gridheight = 1; workzone.add(S2, c); //S3 c.gridx = 2; c.gridy = 1; c.gridwidth = 2; c.gridheight = 1; workzone.add(S3, c); //S4 c.gridx = 4; c.gridy = 0; c.gridwidth = 2; c.gridheight = 2; workzone.add(S4, c); //S5 c.gridx = 7; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; workzone.add(S5, c); //S6 c.gridx = 7; c.gridy = 1; c.gridwidth = 2; c.gridheight = 1; workzone.add(S6, c); //S7 c.gridx = 8; c.gridy = 0; c.gridwidth = 2; c.gridheight = 2; workzone.add(S7, c); //S8 c.gridx = 0; c.gridy = 2; c.gridwidth = 5; c.gridheigth = 1; workzone.add(S8, c); //S9 c.gridx = 6; c.gridy = 2; c.gridwidth = 5; c.gridheight = 1; workzone.add(S9, c); </code></pre> <p>Any ideas and propositions are welcome !</p>
    singulars
    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