• 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

Show JButton with ImageICon in a JTable Cell

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, everybody:
I am new to the forum. I am trying to develop JButtons that with image icons in a JTable cells. And want to addActionListener to the buttons in the cell.
But so far, I could either be able to show imageicons on button but not be able to add actionListener to it, or can have actionListener functioning but shows the default gray buttons. Does anybody has experience on it, it would be great if u can post your code. (Also couldn't adjust teh button cell column width). Those CellRender and CellEditor are very hard for me to understand, does anybody has a good suggestion of reference book or web site?
Thanks a lot and have a good weekend.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class ButtonRenderer extends JButton implements TableCellRenderer
{
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
setIcon(icon);
return this;
}
}

use tableColumn.setCellRenderer(new ButtonRenderer());
 
Jane Green
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot. Just came back from vacation and got your reply.
It helps. I tried to put 'setIcon' in ButtonEditor, never tried to put it in ButtonRender, it's working now.
But there's other problems: 1. I can't set the width of the column that has the button inside. Column.setPreferredWidth(50) doesn't work.
2. When I pressed the button, it shows the gray background although i've set the background to white.
Any idea about those?
Thanks a lot.
[ September 17, 2003: Message edited by: rabbit grass ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rabbit grass" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic