Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can anyone help me out to set image to JTable dynamically.  RSS feed

 
hafz Khan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I want to change image in the JTable cell dynamically.can any one please tell me how to do it.. can i use something similar to setvalue() in defaulttreetablemodel to change the image.. my requirement is that i have to lock certain cells dynamically as user set locks by selecting certain cells in the JTable and at that time i have to insert some images that displays lock and stop the cells from editing..is that possible..?

Your comments are really really appreciated.
Thanks a lot,
Hfz
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can change the appearance of a table cell by using a custom renderer for your table cells. You'll also want to not allow the cell to be editable which can be done by overriding isCellEditable method of your table model and have it return false for the locked cells.

Edit: welcome to JavaRanch by the way! I think though that you'll want to change your name. Please read the FAQ's for more information about the policies and rules here. Enjoy your stay and much luck!
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you insert Icon instances in the TableModel, and return Icon.class from getColumnClass, you won't need a custom renderer as there's already a default renderer for Icons.
 
hafz Khan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I was able to insert an image to jtable ..but my problem is how i could change the image dynamically at the time of an button click..is there any way..it will be very helpful for me if you provide an sample code ..

Thanks for your value replies,
Hafz,
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hafz Khan wrote:Hi All,

I was able to insert an image to jtable ..but my problem is how i could change the image dynamically at the time of an button click..

We already gave you possible solutions, and it is fine to do these "dynamically" with button pushes.

is there any way..it will be very helpful for me if you provide an sample code ..

It's probably best if we work from your code.

Much luck!
 
hafz Khan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pete stein,

Thanks for your reply..i feel little difficulty in pulling out the needed code from the whole..so will you please sent some code by which i can change the icon in the cell..similar to Jtable.setValueAt("pete stein",row,column) which i am using for setting string value in the cell..

ThankYou,
Hafz.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hafz Khan wrote:Hi pete stein,
Thanks for your reply..i feel little difficulty in pulling out the needed code from the whole..so will you please sent some code by which i can change the icon in the cell..similar to Jtable.setValueAt("pete stein",row,column) which i am using for setting string value in the cell..


Please reconsider as you are asking for free advice, which is fine, but are also asking the volunteers here to take time and effort to produce code for you, but have declined to do the same, to take the effort to produce a small compilable code for them to inspect and analyze, and this when it is your problem we are trying to fix. I believe that we'll be able to go much further with your code, and I think that you'll learn much more with the effort.

Much luck!
 
hafz Khan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pete stein,

sorry for the earlier reply..i was using JXTreeTable which is extended from JTable ..as my code was not written neatly and it will confuse you all more thats why i have not posted it...now i have got a sample example for inserting Imageicon..let me try with that.. if the problem still persists i will get back to you..Thanks for your reply...

ThankYou,
Hafz.
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
some code by which i can change the icon in the cell..similar to Jtable.setValueAt("pete stein",row,column) which i am using for setting string value in the cell..


Changing an Icon is no different than changing a String value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!