2
I add a few buttons like this:
JButton bt;
for(int i = 0; i <= 10; i++){
bt = new JButton("BT : " + i);
bt.setPreferredSize(new Dimension(80, 80));
bt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// fazer algo
}
});
jPanel.add(bt);
}
I need an action for each button, let me give you a very simple example. Let’s assume that I have a 10 position vector, with numbers from 1 to 10. That is, I have a position in the vector for each button inserted. When clicking on the right button display the vector position number for the clicked button.
Button 1 - displays vector position 1 Boot 2 - displays vector position 2 Boot 3 - displays position 3 of vector .... and so on
How can I do this in the boot click event?
Possible duplicate of Dynamically generating buttons
– user28595