我想创建 100 个 JToggleButtons 并使用 for 循环来完成并将它们保存在链接列表中。然后在网格包布局中显示它们。
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);
}
我试过类似的东西,但我做不到。