Help with GridBagLayout and GridBagConstraint.anchor

Hi i have this code that construct a JPanel:

private JPanel getUserPassPanel(){

if (userPassPanel ==null){

GridBagLayout gridBagLayout =new GridBagLayout();

userPassPanel =new JPanel();

userPassPanel.setLayout(gridBagLayout);

EmptyBorder emptyBorder =new EmptyBorder(new Insets(10,10,10,10));

userPassPanel.setBorder(emptyBorder);

GridBagConstraints c =new GridBagConstraints();

c.fill = GridBagConstraints.HORIZONTAL;

c.insets =new Insets(2,2,2,2);

//This is my dude, for position the components at top of the panel

//I dont nkow that c.anchor must be set to NORTH for set the components at the top of my JPanel, and when i maximized it, the components maintain at the top.

//at nkow the components staty on the center of my JPanel

c.anchor = GridBagConstraints.NORTH;

c.gridheight = 1;

c.gridwidth = 1;

c.gridx = 0;

c.gridy = 0;

c.weightx = 0;

c.weighty = 0;

userPassPanel.add(getLblCuenta(), c);

c.gridx = 1;

c.gridy = 0;

c.weightx = 1;

c.weighty = 0;

userPassPanel.add(getTxtCuenta(), c);

}

return userPassPanel;

}

with this code, my two componens drws in the center of JPanel, how can i make that the components paint it at top of my JPanel, not at center.

This JPanel is visualized in a JFrame with this code:

initialize is a method of a JFrame

privatevoid initialize(){

this.setSize(300, 200);

this.setLayout(new BorderLayout());

this.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

this.add(getUserPassPanel(), BorderLayout.CENTER);

this.add(getLoginButtonPanel(), BorderLayout.SOUTH);

}

[2437 byte] By [kerulea] at [2007-11-27 1:36:28]
# 1
Hi, As I understood your problem (which was not easy), the button appears in the center of the panel instead of its north.Then, just add a rigid area in your panel.See Box.createRigidAreaHope that help, Jack
jack@square6a at 2007-7-12 0:46:01 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hi, thanks for your answer

Im try it, but i dont nkow were must i add the Box component.

Must i add a Box.createRigidArea before the layout of my panel? were i add it?

And what my example dont work?, in the swing tutorial don磘 explain nothing about Box.createRigidArea whe use GridBagLatout, i follow this tutorial and i dont know why my code not work

thanks again

kerulea at 2007-7-12 0:46:01 > top of Java-index,Desktop,Core GUI APIs...
# 3
may be you want to try something like thisthis.add(getUserPassPanel(), BorderLayout.NORTH);this.add(Box.createRigidArea(new Dimension(50,50), BorderLayout.CENTER);this.add(getLoginButtonPanel(), BorderLayout.SOUTH);
cantrya at 2007-7-12 0:46:01 > top of Java-index,Desktop,Core GUI APIs...