Guest User

Untitled

a guest
Jan 15th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. private class Renderer extends DefaultTableCellRenderer
  2. {
  3. private static final long serialVersionUID = 1L;
  4. @Override
  5. public Component getTableCellRendererComponent(JTable table, Object value,
  6. boolean isSelected, boolean hasFocus,
  7. int row, int column)
  8. {
  9. super.getTableCellRendererComponent(table, value, isSelected,
  10. hasFocus, row, column);
  11.  
  12. int columnIndex = table.getSelectedColumn();
  13. int rowIndex = table.getSelectedRow();
  14.  
  15. if (columnIndex != -1 && rowIndex != -1){
  16. this.setBackground(Color.BLUE);
  17. } else {
  18. if (row % 2 == 0) this.setBackground(Color.decode("0xF9F9F9"));
  19. else this.setBackground(Color.decode("0xF1F1F1"));
  20. }
  21. return this;
  22. }
  23. }
  24.  
  25. if (!isSelected) {
  26. setBackground(...);
  27. }
  28.  
  29. HighlighterPipeline highlighters = new HighlighterPipeline();
  30. highlighters.addHighlighter(new AlternateRowHighlighter());
  31. table.setHighlighters(highlighters);
  32.  
  33. JXTable table;
  34. Highlighter alternateStriping =
  35. HighlighterFactory.createAlternateStriping( Color.decode( "0xF9F9F9" ),
  36. Color.decode( "0xF1F1F1" ) );
  37. table.setHighlighters( alternateStriping );
Add Comment
Please, Sign In to add comment