GridbagLayout (Top Left to Bottom)
Hi
I can't figure out why the following code is ignored
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
I want the labels as they are currently, but just starting in the left top corner.
The default anchor according to the documentation is CENTER, but it seems to have no effect changing it.
package demo.layoutmanagers;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JLabel;
publicclass TopDownGridbagLayout{
/**
* @param args
*/
publicstaticvoid main(String[] args){
JFrame frame =new JFrame();
frame.setSize(500,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout gbl =new GridBagLayout();
GridBagConstraints gbc =new GridBagConstraints();
frame.getContentPane().setLayout(gbl);
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
gbc.insets =new Insets(0,0,0,10);
gbc.gridx = 0;
gbc.gridy = 0;
frame.getContentPane().add(new JLabel("Label One"),gbc);
gbc.gridx = 1;
gbc.gridy = 0;
frame.getContentPane().add(new JLabel("Label Two-Two"),gbc);
gbc.gridx = 0;
gbc.gridy = 2;
frame.getContentPane().add(new JLabel("Label Three"),gbc);
gbc.gridx = 1;
gbc.gridy = 2;
frame.getContentPane().add(new JLabel("Label Four"),gbc);
frame.setVisible(true);
}
}
Thanks

