2

here are the screenshots of the application

This is how it look like when we run it

I want to make it like this

Rows will be displayed in the Table according to the text which is written in the search textfield. Now i want to mark that particular text as per the shown in the second image with the yellow color I know how to select a row or a particular cell. but I don't know how to select a particular text inside the cell of any row in the table.

I am guessing you know how to search in JTable, so I am not pasting code of it here.

Juvanis
  • 25,802
  • 5
  • 69
  • 87
Deepak Odedara
  • 481
  • 1
  • 3
  • 12
  • 4
    [Editors and Renderers](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender) !! – AllTooSir Jul 25 '13 at 06:23

2 Answers2

3

You can look over the SwingX library. It has this kind of function as you said predefined it it. You just need to add it to your table. This is where you can find it. Give it a try you will surely like it.

Nitesh Verma
  • 1,795
  • 4
  • 27
  • 46
  • @Deepak Odedara yeah, SwingX _basically_ supports visual decorations (via Highlighter/-Predicate) - your particular requirement is provided by our [X/MatchingTextHighlighter](https://java.net/projects/swinglabs-demos/sources/svn/show/trunk/SwingXSet6/swingxdemos/src/org/jdesktop/swingx/demos/search?rev=1326) which never made it out off the demos :-) Working fine, probably has problems with RToL – kleopatra Jul 25 '13 at 06:57
3

The basic premise would be to use a custom TableCellRenderer that provided the functionality that you require.

The problem is how to implement it.

I would create a TableCellRenderer based on a JTextField, remove it's border and make it transparent. This will allow you to use the text highlighting functionality provided by JTextCompoent to highlight portions of the text, as demonstrated here.

The next problem is then knowing what to highlight. There are a number of possibilities.

You could provide a method in your table model that could return the current text that should be highlighted.

I'd, personally, probably use the JTable#putClientProperty and JTable#getClientProperty methods to seed the search text.

Or, you could actually provide a simple model that directly to the renderer which had a method that returned the current search text. This might actually be more useful as you could link it to field, the method building the filter and the renderers and allow them to simply seed each other

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • see [here(easier)](http://stackoverflow.com/a/16740520/714968) and [here](http://stackoverflow.com/questions/6410839/highlights-substring-in-the-tablecells-which-is-using-for-jtable-filetering), – mKorbel Jul 25 '13 at 07:16
  • @mKorbel I knew SwingX could do row/column highlighting wasn't sure if it could selective highlighting though – MadProgrammer Jul 25 '13 at 07:18
  • 1
    I'not talking about SwingX, forgot about, just about Html and Regex, even (@kleopatra) is around – mKorbel Jul 25 '13 at 07:20
  • SwingX highlighters can do ... everything :-) They just need to be implemented, exact textMatching is not provided by default, but available - [see my comment to the other] answer(http://stackoverflow.com/a/17850598/203657) – kleopatra Jul 25 '13 at 09:19
  • @kleopatra you know very well that I love SwingX, I want to hightlighing simple and clear way by Rob and Html – mKorbel Jul 25 '13 at 10:58