0

I have a class that extends AbstractTableModel and I'd like to insert a JPanel with clickable text (think hyperlink) into one of the cells. Is this possible? Currently the output in my cell with JPanel looks like "javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,ali..." I've used the same type of JLabel elsewhere in my application to open up new tabs and would like to have the same type of action in my table.

    public Object getValueAt(int row, int column) {
           if (row >= getRowCount()) return "???";
           switch (column) {
                  case 1:
                        return "???"
                  case 2:
                        return myJPanel;
                  case 3:
                        return "?" ;
                  case 4:
                        return new Integer(2);
                  default:
                        return "???" ;
          }
   }
mKorbel
  • 109,525
  • 20
  • 134
  • 319
MCR
  • 1,633
  • 3
  • 21
  • 36
  • 2
    You are looking for a [TableCellRenderer](http://docs.oracle.com/javase/7/docs/api/javax/swing/table/TableCellRenderer.html) rather than an `AbstractTableModel`. See this [example](http://java-swing-tips.blogspot.ie/2009/02/hyperlink-in-jtable-cell.html) – Reimeus Feb 15 '13 at 21:26

1 Answers1

1

This isn't how table models work. Table models model data. They provide information back to the view of the structure and type of data.

It's up to the view to use this information and decide how it should be displayed.

What you are after is the role of the table cell renderer and editor.

Take a look at how to use tables for more details

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366