Alignment Problem



In this function I'm trying to clear out and refill a panel with
buttons.

I want the buttons to be packed together at the top of the panel but it
keeps drawing them in the center.

Could someone possibly tell me what I'm doing wrong?

public void refreshView(){
removeAll();

GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();

this.setLayout(gbl);

gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.NORTH;

for(int i=0;i<Buttons.size();i++){
gbl.setConstraints((JButton)Buttons.get(i),gbc);
add((JButton)Buttons.get(i));
gbc.gridy++;
}
invalidate();
validate();
repaint();
}

.


Quantcast