File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable

 
ramesh kancherla
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently your not adding a MouseListener (or MouseAdapter) but an instance of table.TableIcon.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic