I am trying to create a java swing panel with variable number of buttons on it(1-10000 buttons). However, it seems there is a limitation to the number of buttons I can show in the form and the buttons seem to repeat after a while. I have looked into the tutorials available on Java Swing. However, it does not extend to the number of buttons I am expected to deal with.
This is the code I have written so far.
public JPanel createBlockGroup() {
JPanel blockPanel = new JPanel();
Dimension buttonDimension = new Dimension(40,70);
GroupBlockJNI group = new GroupBlockJNI();
System.out.println(group.getTotalBlockGroups());
blockPanel.setMaximumSize(new Dimension(group.getTotalBlockGroups()*50, 100));
blockPanel.setSize(group.getTotalBlockGroups()*50, 100);
for(int i=0; i<group.getTotalBlockGroups(); i++) { // getTotalBlockGroups() returns 6400
final int j=i;
JButton partition = new JButton("Block Group");
partition.setPreferredSize(buttonDimension);
partition.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2) {
updateLevel(gCurrentLevel+1);
gButtonZoomOut.setEnabled(true);
} else if(e.getClickCount() == 1) {
updateText("Block Group "+String.valueOf(j));
}
}
});
blockPanel.add(partition);
}
return blockPanel;
}
When running this code, I am able to display only 574 buttons. This is the snapshot.
Any help is appreciated.