Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>anchor = NORTH</code> works like a charm:</p> <pre><code>import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class TestJPanels { private JLabel refPlusType; private JTextField addressLine1; protected void initUI() { final JFrame frame = new JFrame(TestJPanels.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridBagLayout()); // 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;"); GridBagConstraints refPlusTypeGC = new GridBagConstraints(); refPlusTypeGC.gridwidth = GridBagConstraints.REMAINDER; // Number of colums occupied by component refPlusTypeGC.insets = new Insets(5, 10, 5, 10); // Specifies margin refPlusTypeGC.weightx = 1; // Required for anchor to work. refPlusTypeGC.anchor = GridBagConstraints.PAGE_START; // Position in container // addressLine1 properties addressLine1 = new JTextField(20); GridBagConstraints addressLine1GC = new GridBagConstraints(); addressLine1GC.insets = new Insets(0, 10, 0, 10); addressLine1GC.fill = GridBagConstraints.HORIZONTAL; // Specifies component fill Horizontal space addressLine1GC.weightx = 1; addressLine1GC.weighty = 1; addressLine1GC.anchor = GridBagConstraints.NORTH; // Add components to this HALLogisticsDetailsPanel panel.add(refPlusType, refPlusTypeGC); panel.add(addressLine1, addressLine1GC); frame.add(panel); frame.setSize(600, 600); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new TestJPanels().initUI(); } }); } } </code></pre>
    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.
    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.
    3. 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