JButton Action Listeners Events
Hi all
I have a question regarding action events... Is it possible for a
button to have multiple events generated??... I have been wanting to
generate two events from clicking a single button ..My following
sample code has the Add Row button and Up button that generates
separate events but I would like a single Up button to generate adding
a row below as well as insertion of a row if there are entries say
between table cells A and C it should insert a cell in between
(functionality like Excel)......
How do I do this? Pls help!!
button = new JButton( "Add Row" );
buttonPanel.add( button );
button.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
model.addRow( createRow() );
int row = table.getRowCount() - 1;
table.getColumnModel().getColumn(4).setCellEditor(new
DefaultCellEditor(comboBox));
table.changeSelection(row, 0, false, false);
table.requestFocusInWindow();
}
});
//
button = new JButton( "Up" );
buttonPanel.add( button );
button.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int row=table.getSelectedRow();
model.insertRow(row, createRow() );
table.changeSelection(0, 0, false, false);
table.requestFocusInWindow();
}
});