Guest User

Untitled

a guest
Oct 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1.  static class Renderer extends JPanel implements TableCellRenderer {
  2.         public Renderer() {
  3.             super();
  4.             setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  5.         }
  6.  
  7.         public Component getTableCellRendererComponent(JTable table,
  8.                 Object value, boolean isSelected, boolean hasFocus, int row,
  9.                                                                 int column) {
  10.             if (value == null)
  11.                 return null;
  12.             JLabel label = new JLabel(value.toString());
  13.             label.setAlignmentX(Component.CENTER_ALIGNMENT);
  14.             add(label);
  15.             if (isSelected) {
  16.                 setBackground(table.getSelectionBackground());
  17.                 setForeground(table.getSelectionForeground());
  18.             } else {
  19.                 setBackground(table.getBackground());
  20.                 setForeground(table.getForeground());
  21.             }
  22.             return this;
  23.         }
  24.     }
Add Comment
Please, Sign In to add comment