• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable selected row

 
Duane Riech
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable which is NOT editable, but I do want the background color
to change to indicate that the row has been selected. Notice that I call
setSelectionBackground() but this doesn't do anything.
Thanks...
ItemTable = new JTable( tableDataModel );
ItemTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
ItemTable.setDefaultRenderer( String.class,
new ItemTableCellRender(ItemDisplayData));
ItemTable.setRowSelectionAllowed(true);
ItemTable.setSelectionBackground( Color.BLUE );
ListSelectionModel ItemModel = ItemTable.getSelectionModel();
ItemModel.addListSelectionListener( new ItemSelectionModel() );

ItemTable.setPreferredScrollableViewportSize(new Dimension(500, 650 ));
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have to set the background color in the TableCellRenderer
 
Duane Riech
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply...
Yes, I finally figured it out yesterday.

Thanks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!