0

I am able to display the buttons fine in a JTable; but I am having problems clicking on the button. I tried implementing a mouse listener for the JPanel but that does not work.

This is how i create my table:

     Object[] columnnames = {
            "ID", "Resource Name", "Incident", "Owner", "Action"
           };
     Object[][] sentByMe = //get data;      
     sentByMeTable = 
        new JTable(sentByMe, columnnames){
           public TableCellRenderer getCellRenderer( int row, int column ) {
              return new PlusMinusCellRenderer();
           }
        };

And this is my PlusMinusCellRenderer

      class PlusMinusCellRenderer extends JPanel implements TableCellRenderer {
     public Component getTableCellRendererComponent(
                        final JTable table, Object value,
                        boolean isSelected, boolean hasFocus,
                        int row, int column) {
        this.add( new JLabel( value.toString()  ) );
        JButton button = new JButton("+");
        this.add(button);
        return this;
     }

So what i am having trouble with is being able to click on the buttons. Thanks for all your help in advance.

KrispyDonuts
  • 1,240
  • 2
  • 18
  • 36
  • 1
    You *really* need to start with the tutorials or a beginner's book on java. Building GUIs requires you to understand how the event model works. http://docs.oracle.com/javase/tutorial/uiswing/index.html – Brian Roach Dec 05 '11 at 03:19
  • This should help you http://stackoverflow.com/questions/1475543/how-to-add-button-in-a-row-of-jtable-in-swing-java – sethu Dec 05 '11 at 03:26
  • thanks for the help sethu and brian. i will look into these links. – KrispyDonuts Dec 05 '11 at 03:29

0 Answers0