• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JTable selected row

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ));
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply...
Yes, I finally figured it out yesterday.

Thanks again
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic