This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Highlighting a JTable cell on a successful search for a value entered in a textfield. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Highlighting a JTable cell on a successful search for a value entered in a textfield." Watch "Highlighting a JTable cell on a successful search for a value entered in a textfield." New topic
Author

Highlighting a JTable cell on a successful search for a value entered in a textfield.

Neha D
Ranch Hand

Joined: Oct 12, 2004
Posts: 32
Hi All,

I want to have a feature with JTable wherein I'll provide a textfield to enter a value to be searched from the JTable and if this entered value matches with any of the cell values in the JTable then that particular cell should be highlighted & the cell font should be turned to BOLD. The values will be matched when the user presses Enter key after specifying the value in the text field.

Now I am able to search a value from the JTable, & on a successful search I call the TableCellRenderer. But the thing is on a successful search I try & edit that particular cell so that it is selected. But the method editCellAt(row, column) returns a false. And also how do I give a focus on that particular matched cell. Due to this even if the cell renderer runs it reflects me no change in the JTable cell.

Can anyone plz help me out with this problem. It is very urgent.
All help is appreciated.

Thanx.
Neha......
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Neha D
Ranch Hand

Joined: Oct 12, 2004
Posts: 32
Heyy thanx for the code. But when I tried implementing this code, it blanked out all the cells of the JTable. Could you let me know some other solution for the problem.

Thanx.
Neha......
francis joby
Greenhorn

Joined: Aug 30, 2005
Posts: 6
I have same problem and I have one more. can u set the background color red to table heading.
Sandesh Gowda
Greenhorn

Joined: Jun 04, 2012
Posts: 4
Just add this line to your table and to an actionListener.
JTable myJTable;
myJTable.getSearchable(); //This line implements pops up a search box when you add this line to an actionlistener for (ctrl+f). getSearchable() is a default search function for JTable. it provides, case sensitive/forward/backward search
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4572
    
    5

The question was asked more than 6½ years ago.

Sandesh Shankarappa wrote:Just add this line to your table and to an actionListener.
JTable myJTable;
myJTable.getSearchable(); //This line implements pops up a search box when you add this line to an actionlistener for (ctrl+f). getSearchable() is a default search function for JTable. it provides, case sensitive/forward/backward search

Did you invent that or are you referring to some third party JTable class unfortunately named the same as the one in the standard JDK, javax.swing.JTable?

JTable doesn't have a getSearchable() method. Note: method, not function. Java doesn't have functions.

And welcome to the Ranch!


luck, db
There are no new questions, but there may be new answers.
Sandesh Gowda
Greenhorn

Joined: Jun 04, 2012
Posts: 4
I did not invent it, the function is part of searchable class under swing.

The following line of code pops up a find window with forward/backward/case sensitive search options.
SearchFactory.getInstance().showFindInput(myjTable, myjTable.getSearchable());

I am working on incremental search in jtable and I came across this question, I thought it would help someone like me who is working on searchables in jtable
Do you know how to make getSearchable to forward search from selected row instead of searching from the first row of the table?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

There is no searchable class in Swing, and there is no class SearchFactory in all of JSE.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sandesh Gowda
Greenhorn

Joined: Jun 04, 2012
Posts: 4
hmmm... searchable is mentioned in this link: http://www.jidesoft.com/javadoc/com/jidesoft/swing/Searchable.html#getSearchable(javax.swing.JComponent)
Does anyone know how to implement an incremental search for JTables ?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4572
    
    5

That's a Jidesoft link you posted. Not part of the standard API.

If Jidesoft is open source, you could start a thread in the Other Open Source Projects section. If not, ask wherever you got those classes.
 
GeeCON Prague 2014
 
subject: Highlighting a JTable cell on a successful search for a value entered in a textfield.