3

I want to display a graphic e.g. gif resource and a currency number in a single jtable cell. below is the code for he cell renderer ,it displays the currency as expected but the graphic is distorted in the cell. Any suggestion

 public class CurrencyCellRenderer extends DefaultTableCellRenderer {

     private final ImageIcon cediImage =
         new ImageIcon (getClass().getResource("/resources/images/cedi.gif"));


     public CurrencyCellRenderer() {
         super();
         setHorizontalAlignment(SwingConstants.LEFT); 
     }

     @Override
     public void setValue(Object value) {
         if ((value != null) && (value instanceof Number)) {
             Number numberValue = (Number) value;
             NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("ghs" ,"GH")); 
             value = formatter.format(numberValue.doubleValue());
         }
         super.setIcon(cediImage);
         super.setValue(value);
     }  

}

below is the code attaching the cellrenderer to the table

    jTable.setDefaultRenderer(Double.class , new CurrencyCellRenderer());

thank you all.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
CodeAngel
  • 569
  • 1
  • 11
  • 31
  • 3
    For better help sooner please provide an [MCVE](http://stackoverflow.com/help/mcve) I mean a **full** code but **simple** enough that we can copy-paste it and see the issue you see. Delete unnecesary code such as format like colors, images, etc (if the issue isn't related to them). Good Luck – Frakcool Sep 09 '14 at 23:11
  • Check the size of your icon image. The following article might also contain some helpful information: http://stackoverflow.com/questions/14548808/scale-the-imageicon-automatically-to-label-size – terrywb Sep 09 '14 at 23:44
  • 1
    How to you mean distorted? – MadProgrammer Sep 09 '14 at 23:50
  • 1
    In your [example](http://stackoverflow.com/help/mcve), access posted images via `URL`, as shown [here](http://stackoverflow.com/a/10862262/230513); use synthetic images as shown [here](http://stackoverflow.com/a/15982915/230513); or use `UIManager` icons, as shown [here](http://stackoverflow.com/a/12228640/230513). – trashgod Sep 10 '14 at 01:13

0 Answers0