So I've been getting away from the default layout manager and have been playing with GridBagLayout. I actually like this layout a lot, its a rather simple way to give a complex layout.
My trouble is that I have, say 100 buttons, I'm adding to a JPanel. This JPanel is inside a JScrollPane (So when there are too many buttons, you can scroll to see the rest). I'm trying to use the GridBagLayout manager to add each button to the NORTH. So I set a constraint;
As I understand this, if the Component's Displaying Area (the JPanel) has extra room, this constraint will distribute the extra space based around the constraint. I choose to set mine Centered at the top, which as I understand to be NORTH.Code:c.anchor = GridBagConstraints.NORTH;
When I run this app, the button continues to display in the center.
The above code is not exact, its the pieces I think are important in solving the puzzle. Its the setup, the JPanel and JScrollPane (w/Dimension), and the buttons being added using the constraints.Code:JPanel buttonHolder = new JPanel();
JScrollPane sp = new JScrollPane(buttonHolder);
GridBagConstraints c = new GridBagConstraints();
Dimension d = new Dimension(160,560);
c.gridx = 100;
c.anchor = GridBagConstraints.NORTH;
sp.setPreferredSize(d);
mainPanel.add(sp);
for(int i=0; i<counter; i++){
buttonBuddies[i].setText(buddies[i]);
buttonHolder.add(buttonBuddies[i],c);
}
Thanks for any suggestions
