I want to create 100 JToggleButtons and do it with a for loop and save them in a link list. Then show them in grid bag layout.
ArrayList<JToggleButton> buttons = new ArrayList<JToggleButton>();
for(int i=0; i<100; i++){
buttons.add(new JToggleButton(""));// = new JToggleButton("");
GridBagConstraints gbc_ = new GridBagConstraints();
gbc_tglbtnNewToggleButton.fill = GridBagConstraints.VERTICAL;
gbc_tglbtnNewToggleButton.insets = new Insets(0, 0, 5, 5);
gbc_tglbtnNewToggleButton.gridx = i;
gbc_tglbtnNewToggleButton.gridy = j;
frame.getContentPane().add(tglbtnNewToggleButton, gbc_tglbtnNewToggleButton);
}
I tried something like that, but i can't.
You're not adding the created button to the content pane. And you create a constraint named gbc_, but never use it. Change the code to