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);
}

