0

I need to customize my jTable. All I need, is to put a custom Swing object (like jButon, jPanel, etc.) into the table cell. Is it possible? I'm trying:

jTable.getModel.setValueAt(jPanel1,0,0)

and

jTable.getModel.setValueAt(jPanel1.getUI(),0,0)

But the result is only a some kind of string, representing the object...

I'm aware of custom renderers, but still don't get the technique of registering them properly. How do you do that?

oldhomemovie
  • 14,621
  • 13
  • 64
  • 99
  • 1
    take a look at this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer – akf Mar 20 '10 at 14:12

3 Answers3

3

See How to Use Tables, Concepts: Editors and Renderers in the swing tutorial. It sounds like you're getting the default renderer for Object, which is "rendered by a label that displays the object's string value." You can use setDefaultRenderer to associate your class with your renderer, as shown in this example.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
2

You have to make use of a ListCellRenderer for this, Read a similar question here.

Community
  • 1
  • 1
Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94
2

you can visit this webpage it's reeeeeeally helpful

hecvd
  • 659
  • 1
  • 8
  • 24