Advertisement
Guest User

customTable.java

a guest
Aug 28th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3. import javax.swing.JButton;
  4. import javax.swing.table.DefaultTableModel;
  5.  
  6. public class customTable extends DefaultTableModel{
  7.     Object[][] data;
  8.    
  9.     public customTable(Object[][] data, String[] column){
  10.         super(data, column);
  11.         this.data = data;
  12.     }//End of constructor
  13.    
  14.     public boolean isCellEditable(int row, int cols){
  15.         return false;
  16.     }//End of isCellEditable method
  17.    
  18.     public Object getValueAt(final int rowIndex, final int columnIndex){
  19.         switch(columnIndex){
  20.             case 0: return (String)data[rowIndex][columnIndex];
  21.             case 1: return (String)data[rowIndex][columnIndex];
  22.             case 2: final JButton button = new JButton(((JButton)data[rowIndex][columnIndex]).getText());
  23.                     button.setBorder(null);
  24.                     button.addActionListener(new ActionListener(){
  25.                         public void actionPerformed(ActionEvent ae){
  26.                             System.out.println("Clicked at row " + rowIndex + " and column " + columnIndex);
  27.                             /*  I want this table to invoke action method and gives the row index number */
  28.                             //mainGUI.action(rowindex); //Calls the action method in mainGUI class
  29.                         }//End of actionPerformed method
  30.                     }); //End of anonymous class
  31.                     data[rowIndex][columnIndex] = button;
  32.                 return button;
  33.             default: return "Error";
  34.         }//End of switch statement
  35.     }//End of getValueAt method
  36. }//End of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement