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.
Joined: Sep 20, 2005
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.