aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Getting component in a cell for a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Getting component in a cell for a JTable" Watch "Getting component in a cell for a JTable" New topic
Author

Getting component in a cell for a JTable

thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
My Jtable contains several Jcomponents like the JLabel, JTextButton. Is there a possible way to get the components instance in say eg: row 1 and column 1.

Regards
Thomas
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 852
Does your table model actually contain JComponents, so that calling yourTable.getModel().getValueAt(1, 1) would return something like a JLabel?

If so, then just call yourTable.getModel().getValueAt(row, col). But this is a very weird way to do things. Unless you are writing something like a GUI builder, then I would say it's a mistake to do it this way.

Usually your table model will hold values of type String, Integer, Boolean, and so on. In this case there isn't really a JComponent for any particular row/col. The table will use one or more components to render the value, but it is associated with a particular row/col for only a fleeting moment, then is reused elsewhere. This is how TableCellRenderers work.

What is odd is that you are the third person over the last few days to ask a question about accessing the "component" for a table cell. Either this is a weird coincidence, or the situation is something like you are all in the same class and your instructor hasn't explained things very well.

In any case, there just isn't any kind of "component instance" that you can "get" for a particular row/col, unless you want to get it briefly while rendering or editing is in progress.


bitguru blog
thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
Hi,
I am involved in a forte conversion project. I am trying to implement an ArrayField feature of Forte using the best match JTable in java. The ArrayField has a feature to return a component back
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Getting component in a cell for a JTable
 
Similar Threads
JTable
JTable
JTable
JTable
JTable