• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JTable

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can I insert a image into cell with actions

like I have to insert a iconImage into table cell whenever i clicked icon then it does some actions.
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easy way is have your TableModel return ImageIcon.class or Icon.class for that column. That will render the cell's value as an image.
Next, add a MouseListener to the entire table. Inside its methods, you can call the JTable's columnAtPoint and rowAtPoint methods to find out which cell was clicked. If the column matches then perform the action:
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setCellRenderer() method taking cellRenderer value only

you told as if TableModel returns icon,it will takes into cell

how can i pass this icon into cellrenderer
 
Rob Spoor
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need a custom cell renderer. If your table model returns one of those classes, then JTable will use one of its own internal cell renders to display the icon.

So your table model will have to override getColumnClass:

You can also choose other classes; Number.class and its subclasses will handle numeric conversion as well as right-aligning the number. Boolean.class will use a check box for both rendering and editing. And as said before, ImageIcon.class and Icon.class will use an image.

Please note that the value must be castable to the class, or you will get ClassCastExceptions.
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to add MouseListener to table

addMouseListener(java.awt.event.MouseListener) in java.awt.Component cannot be applied to (table.TableIcon)

I got this error, when I am trying to add MouseListener
 
Rob Spoor
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently your not adding a MouseListener (or MouseAdapter) but an instance of table.TableIcon.
 
Danger, 10,000 volts, very electic .... tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic