Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.table.DefaultTableModel;
- public class customTable extends DefaultTableModel{
- Object[][] data;
- public customTable(Object[][] data, String[] column){
- super(data, column);
- this.data = data;
- }//End of constructor
- public boolean isCellEditable(int row, int cols){
- return false;
- }//End of isCellEditable method
- public Object getValueAt(final int rowIndex, final int columnIndex){
- switch(columnIndex){
- case 0: return (String)data[rowIndex][columnIndex];
- case 1: return (String)data[rowIndex][columnIndex];
- case 2: final JButton button = new JButton(((JButton)data[rowIndex][columnIndex]).getText());
- button.setBorder(null);
- button.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- System.out.println("Clicked at row " + rowIndex + " and column " + columnIndex);
- /* I want this table to invoke action method and gives the row index number */
- //mainGUI.action(rowindex); //Calls the action method in mainGUI class
- }//End of actionPerformed method
- }); //End of anonymous class
- data[rowIndex][columnIndex] = button;
- return button;
- default: return "Error";
- }//End of switch statement
- }//End of getValueAt method
- }//End of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement