• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphics in jtable cell

 
Zach Donovan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i need to put some graphics in to a jtable cell...instead of using imageicons, how do i use the paint(Graphic g) method to go it?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You weren't clear, but I think your passing reference to ImageIcon refers to the fact that if you have an ImageIcon in your TableModel, then the default cell render for that cell gets the ImageIcon to render its own cell. All that's true, but replace ImageIcon with Icon -- the object in your TableModel doesn't have to be a ImageIcon, just an object implementing Icon. So you could define your own Icon class (it's easy) and the graphics code would go in your class's implementation of paintIcon.
 
Zach Donovan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff,

i have resized mt cells using table.setRowHeight and setPreferredWidth() for columns, will the image i put in fill the whole cell?

cheers
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zach Donovan:

i have resized mt cells using table.setRowHeight and setPreferredWidth() for columns, will the image i put in fill the whole cell?


By the time you read my reply here, I'm sure you've already tested this yourself, so you know the answer!
 
Zach Donovan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff,

how do i actually position the image in the center of a cell?

thanks in advance...
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Zach Donovan:

how do i actually position the image in the center of a cell?

The default cell render should be centring your icons. Demo:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!