What could be the effect of Anchor field in GridBagLayout, if the Fill field is set to BOTH ??
In the following program, I am displaying three buttons; the first two at the top left, one below the other and the Third one at the bottom right.
import java.awt.*;
public class AnchorTest extends Frame{
AnchorTest() {
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
Button b = new Button("1st button");
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
//gbc.anchor = GridBagConstraints.WEST;
gbc.gridwidth = 2;
add(b,gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.BOTH;
Button n = new Button("2nd button");
add(n,gbc);
gbc.gridx = 2;
gbc.gridy = 2;
Button n2 = new Button("3rd button");
add(n2,gbc);
setSize(150,150);
setVisible(true);
}
public static void main(
String[] args){
new AnchorTest();
}
}
I don't see any difference in the output even if I include the commented anchor field.
If I set the fill field to NONE (by commenting that line), I am seeing the effect of anchor field.
Can someone explain the purpose of anchor field in detail ??
Thanks
Regards
Balaji