Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

detect if JTable column contains string "blabla"  RSS feed

 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which classes related to the JTable should i use so i can check if a table column contains a certain string
 
Renjith mohanan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark ,

I think you can use the DefaultTableCellRenderer class
And this class has a method
public Component getTableCellRendererComponent(JTable table,Object obj, boolean isSelected, boolean hasFocus, int row, int column)
You can ovrride the method and can check table value......

Thanks
Renjith M
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi tv, thanks. yes you are right.

but what i want to do is something like this

jTable.getColumn("column_name").doesStringExistInColumn(); returns boolean

something like that.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T.V.M Renjith wrote:
I think you can use the DefaultTableCellRenderer class
public Component getTableCellRendererComponent(JTable table,Object obj, boolean isSelected, boolean hasFocus, int row, int column)


Not really.
The renderer is like a rubber stamp for the visualization part and the method you mention returns a visual component.
Remember MVC. The visualization should be independent of the data.

The proper way to do it would be to query the table model for the required data.
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.

been searching but found no possible way to shorten the solution. so i used getValueAt() and checked each row of the tablemodel.
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark chester goking wrote:thanks.

been searching but found no possible way to shorten the solution. so i used getValueAt() and checked each row of the tablemodel.


Bingo!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!