0

i created some costum cells render to change the look of my jtable, i changed color of some rows, and font, i tried to do the same but it doesn't work, this is my code :

@Override
            public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                Component c = super.prepareRenderer(renderer, row, column);
                int firstRow = 0;
                int lastRow = jTable1.getRowCount() - 1;
                if (row == lastRow) {
                    ((JComponent) c).setBackground(new Color(218, 244, 247));
                //((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
                } else if (row == firstRow) {
                    ((JComponent) c).setBackground(new Color(218, 244, 247));
                    ((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
                     ((JComponent) c).setForeground(new Color(11, 114, 126));
                } else if (row == 5) {
                    ((JComponent) c).setBackground(new Color(218, 244, 247));
                    ((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
                } else {
                    ((JComponent) c).setBackground(jTable1.getBackground());
                }

                return c;
            }

This is when i face the problem :

((JComponent) c).setForeground(new Color(11, 114, 126));

if (row == firstRow) {
((JComponent) c).setBackground(new Color(218, 244, 247));
((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
((JComponent) c).setForeground(new Color(11, 114, 126));}

Thanks

mKorbel
  • 109,525
  • 20
  • 134
  • 319
archavin
  • 313
  • 2
  • 5
  • 12
  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Please add an upper case letter at the start of sentences. Also use a capital for the word I, and abbreviations and acronyms like JEE or WAR. This makes it easier for people to understand and help. – Andrew Thompson Jun 11 '13 at 11:03

1 Answers1

1

, i changed color of some rows, and font, i tried to do the same but it doesn't work, this is my code :

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • you are right, but my table shouldn't be reordered or sorted.data is from database, but with some restriction and filtring. i think Renderer will work for me (i hope so) – archavin Jun 11 '13 at 11:21