• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic