-3
static class DateRenderer extends DefaultTableCellRenderer {
        DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
        public DateRenderer() { super(); }

        public void setValue(Object value) {
            if (formatter==null) {
                formatter = DateFormat.getDateInstance();
            }
            setText((value == null) ? "" : formatter.format(value));
        }
    }

I use this code to render dates. I found it as this but now i need something else. I have a column with numbers as this (1234.56). I want to render the numbers as (1234.56 TL). But i am kinda beginner so i can't find the way to do it.

Gresta
  • 72
  • 8
  • Does this answer your question? [Set Jtable/Column Renderer for booleans](https://stackoverflow.com/questions/2879559/set-jtable-column-renderer-for-booleans) – Oliver Aug 24 '20 at 05:17
  • When I put 'JTable custom column renderer' in my fave search engine, the third link is to [How to Use Tables](https://docs.oracle.com/javase/tutorial/uiswing/components/table.html) in the Java Tutorials. It shows how and includes example code. – Andrew Thompson Aug 24 '20 at 05:19
  • @Oliver i guess it is for components mostly. I just need to render the value. And even if it is the answer i am not that good to understand. – Gresta Aug 24 '20 at 05:26
  • @AndrewThompson i already did check it before but the codes are abouth changing colors so i just cant understand. – Gresta Aug 24 '20 at 05:28
  • @OleV.V. thanks for the tip. I just did it. – Gresta Aug 24 '20 at 06:39
  • 1
    (1-) you were already given the answer to this in your last question: https://stackoverflow.com/questions/63487326/how-can-i-make-a-tablerowshorter-between-two-date. Did you not read the entire link that showed how to format numbers as well??? – camickr Aug 24 '20 at 13:09
  • @camickr i did but it is kinda complex for me to understand. – Gresta Aug 24 '20 at 14:37

1 Answers1

1
TableColumnModel m = table.getColumnModel();
m.getColumn(5).setCellRenderer(new TableRendererExample());
 class TableRendererExample extends DefaultTableCellRenderer {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
          Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
          if (column == 5) {
            setText(value.toString()+" TL");
          }
          return this;
        }
      }

This code works fine for answer.

Gresta
  • 72
  • 8