Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Color Some particular rows in JTable

 
Rachit Vaish
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All need help

I have a table and i have to implement a search functionality in that table for that i have created search button and performed search operation. Now i want that all rows who are having search values must change their color please help me with that problem example is here------

Now Assume that i have searched vinod then the entire row of vinod must change its colour...
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future, while posting code, please UseCodeTags I have added them for for you this time. As you can see, the tags make the code much more easier to read and understand.

Coming back to your question, what you need is renderers. Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#renderer
 
Rachit Vaish
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:In future, while posting code, please UseCodeTags I have added them for for you this time. As you can see, the tags make the code much more easier to read and understand.

Coming back to your question, what you need is renderers. Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#renderer


Thanks for your suggestion but i think exact answer in the code form will be more helpful....
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are looking for ready made code, then unfortunately, the Ranch is not the place. We are NotACodeMill because we believe the best way to learn is to be guided along the way and not being spoon fed.
Why don't you give the code a shot, and try it out. If you still can't get it right, you can post your SSCCE and we will help you figure out what's wrong with that code.
Best of luck!
 
Rachit Vaish
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:If you are looking for ready made code, then unfortunately, the Ranch is not the place. We are NotACodeMill because we believe the best way to learn is to be guided along the way and not being spoon fed.
Why don't you give the code a shot, and try it out. If you still can't get it right, you can post your SSCCE and we will help you figure out what's wrong with that code.
Best of luck!


I am not looking for a ready made code. I just want a help in any form like explain(a little) the calling of required methods as till now i am familiar with one method " getTableCellRendererComponent(JTable,Object,boolean,row,column) " but i am not getting the way how to use it. I mean i have go through with many example where this method is used, but i am unable to understood its working....
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rachit Vaish wrote:i am not getting the way how to use it. I mean i have go through with many example where this method is used, but i am unable to understood its working....

It's a method defined in the inteface TableCellRenderer, that receives 6 parameters (not 5 as you have listed). The method is expected to make use of those parameters to returna java.awt.component subclass that is to be used by the caller to paint that cell in the JTable.

How it works -- what it returns -- is governed by the code inside the method, usually in conjunction with instance and/or static fields of the implementing class.

A common way to create a custom TableCellRenderer is by extending DefaultTableCellRenderer, a JLabel subclass. In such implementations, it is common to override the method something like:To create a custom renderer that isn't a JLabel, you can either extend the class of interest or maintain an instance of it as a field, and implement TableCellRenderer.

You can gain some more knowledge by reading the source of DefaultTableCellRenderer, will you will find in the src.zip in your JDK installation folder.
 
Rachit Vaish
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Rachit Vaish wrote:i am not getting the way how to use it. I mean i have go through with many example where this method is used, but i am unable to understood its working....

It's a method defined in the inteface TableCellRenderer, that receives 6 parameters (not 5 as you have listed). The method is expected to make use of those parameters to returna java.awt.component subclass that is to be used by the caller to paint that cell in the JTable.

How it works -- what it returns -- is governed by the code inside the method, usually in conjunction with instance and/or static fields of the implementing class.

A common way to create a custom TableCellRenderer is by extending DefaultTableCellRenderer, a JLabel subclass. In such implementations, it is common to override the method something like:To create a custom renderer that isn't a JLabel, you can either extend the class of interest or maintain an instance of it as a field, and implement TableCellRenderer.

You can gain some more knowledge by reading the source of DefaultTableCellRenderer, will you will find in the src.zip in your JDK installation folder.


Thank you sir it is quite helpful for me, but i am still not able to use this method with my class as i have mentioned in my example, as we cannot call this method then how can we use it....??
 
Rachit Vaish
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rachit Vaish wrote:
Darryl Burke wrote:
Rachit Vaish wrote:i am not getting the way how to use it. I mean i have go through with many example where this method is used, but i am unable to understood its working....

It's a method defined in the inteface TableCellRenderer, that receives 6 parameters (not 5 as you have listed). The method is expected to make use of those parameters to returna java.awt.component subclass that is to be used by the caller to paint that cell in the JTable.

How it works -- what it returns -- is governed by the code inside the method, usually in conjunction with instance and/or static fields of the implementing class.

A common way to create a custom TableCellRenderer is by extending DefaultTableCellRenderer, a JLabel subclass. In such implementations, it is common to override the method something like:To create a custom renderer that isn't a JLabel, you can either extend the class of interest or maintain an instance of it as a field, and implement TableCellRenderer.

You can gain some more knowledge by reading the source of DefaultTableCellRenderer, will you will find in the src.zip in your JDK installation folder.


Thank you sir it is quite helpful for me, but i am still not able to use this method with my class as i have mentioned in my example, as we cannot call this method then how can we use it....
I have also seen use of prepareRenderer(TableCellRenderer,row,col) but i am not able to use it in my code.....
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic