codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  How to highlight text WITHIN a JTable cell?  MarkHausman at 22:27 on Monday, December 08, 2008
 

I am writing a search/replace function that is intended to work with Swing JTables which contains Strings. I would like to be able to highlight a substring WITHIN a cell, if that substring is the sought-for value.
For example, if a single cell contained "Now is the time", I would like to be able to highlight "the".

With the following code I can programmatically "select" characters 7-9 of the String:
table.editCellAt(row, col);
DefaultCellEditor ed = (DefaultCellEditor)table.getCellEditor();
JTextField jf = (JTextField)ed.getComponent();
jf.select(7, 10);
However, this does not visibly highlight the text; it merely sets the (invisible) caret to these character positions, so when the user begins to type characters 7-9 are replaced.









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
• C++
• Re: refresh parent after closing pop up window
• Dynamic Insertion
• Date and Time function around the world???
• Significant Factors
• Perl array access
• Re: huffman encoding and decoding in C++...
• Perl One Liner: Replace {(
• Re: html including php, accessing the functions


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009