Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, I got it. I don't like accepting my own answers but here we go. At the end of the day I am trying to get the whole lot to bunch together properly at the top of the container. Adding <code>weighty</code> attributes to all the components individually means that the remaining space in the container is distributed between all of them (relative to their <code>weighty</code> attribute) therefore spacing them out.</p> <p>The answer seems to be that by adding a <code>weighty</code> attribute to the lowest component in the GridBagLayout, the rest of the remaining space is allocated to below the lowest component and therefore pushing all components to the top. By default is seems that when remaining space is allocated to a component based on it's weight, it is allocated <strong>below</strong> it (at least on the y axis).</p> <p>Here is the new code with three components to help demonstrate;</p> <pre><code> // Instantiate components and configure their corresponding GridBagConstraints attributes // refPlusType properties refPlusType = new JLabel("&lt;html&gt;&lt;h3&gt;"+"Reference"+" - "+"Job Type"+" &lt;/h3&gt;&lt;hr /&gt;&lt;/html&gt;"); refPlusTypeGC = new GridBagConstraints(); refPlusTypeGC.gridx = 0; // Grid position refPlusTypeGC.gridy = 0; refPlusTypeGC.gridwidth = 2; // Number of colums occupied by component refPlusTypeGC.insets = new Insets(5, 10, 5, 10); // Specifies margin // addressLine1 properties addressLine1 = new JTextField(); addressLine1GC = new GridBagConstraints(); addressLine1GC.gridx = 0; addressLine1GC.gridy = 1; addressLine1GC.gridwidth = 2; addressLine1GC.insets = new Insets(0, 10, 0, 10); addressLine1GC.fill = GridBagConstraints.HORIZONTAL; // Specifies component fill Horizontal space // addressLine2 properties addressLine2 = new JTextField(); addressLine2GC = new GridBagConstraints(); addressLine2GC.gridx = 0; addressLine2GC.gridy = 2; addressLine2GC.gridwidth = 2; addressLine2GC.insets = new Insets(0, 10, 0, 10); addressLine2GC.fill = GridBagConstraints.HORIZONTAL; // Specifies component fill Horizontal space addressLine2GC.weighty = 1; // Required for anchor to work. addressLine2GC.anchor = GridBagConstraints.NORTH; // Position in container // Add components to this HALLogisticsDetailsPanel this.add(refPlusType, refPlusTypeGC); this.add(addressLine1, addressLine1GC); this.add(addressLine2, addressLine2GC); </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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