Ich habe mir in einem Programm Dynamisch eine paar Buttons erstellt, wie weise ich jetzt diesen Buttons wieder Dynamisch eine Event zu?
Ich hoff ihr versteht was ich meine.
Ich hoff ihr versteht was ich meine.
public void setTableBtn ( ) {
new SwingWorker(){
@Override
protected Object doInBackground() {
tblModel = new PortTableModel(connection, columnNames, tableCount);
Object tablecount = (tblModel.getValueAt(0, 0));
String tablecountStr = tablecount.toString();
try {
tableCounttoint = Integer.parseInt(tablecountStr); //
}
catch (Exception E) {
}
javax.swing.JButton[] buttons = new javax.swing.JButton[tableCounttoint];
for (int i = 1; i<tableCounttoint; i++) {
buttons[i] = new javax.swing.JButton("btnTabel"+i);
tabelPanelDyn.add(buttons[i]);
buttons[i].setText("# " + i);
buttons[i].setSize(50, 23);
buttons[i].setVisible(true);
buttons[i].ac
}
tabelPanelDyn.validate();
return null;
}
}.execute();
// Resulttable = ((PORTFrame) portframe).connection.createStatement().executeQuery(tablecount);
}
buttons[i].addActionListener(...)
final int number = i;
buttons[i] = new javax.swing.JButton("btnTabel"+i);
buttons[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.prinlnt("Number: "+number);
}
}
Marco13 hat gesagt.:Schau vielleicht auch mal hier drüber - das dürfte ziemlich genau das sein, was du brauchst...
http://www.java-forum.org/de/viewtopic.php?p=310844