JTable with row selection, but no cell selection

  • Thread starter Simon Niederberger
  • Start date
S

Simon Niederberger

I have a JTable where I want the user to be able to select a row, but not a
single cell. If the user clicks on a cell, the entire row should be
highlighted (=different background color), but the CellEditor shouldn't come
up.

JTable table = new JTable();

// this wil disable cell selection, but also the row
// highlighting disappears
table.setCellSelectionEnabled(false);

Thanks
Simon
 
A

Andrey Kuznetsov

I have a JTable where I want the user to be able to select a row, but not a
single cell. If the user clicks on a cell, the entire row should be
highlighted (=different background color), but the CellEditor shouldn't
come
up.

JTable table = new JTable();

// this wil disable cell selection, but also the row
// highlighting disappears
table.setCellSelectionEnabled(false);

table.setRowSelectionAllowed(true);
 
C

Christian Kaufhold

Followup-To: comp.lang.java.gui.

Simon Niederberger said:
I have a JTable where I want the user to be able to select a row, but not a
single cell. If the user clicks on a cell, the entire row should be
highlighted (=different background color), but the CellEditor shouldn't come
up.

You a) change the renderer not to paint editable cells in a special
background color and b) configure the editor not to start editing
on single mouse clicks.


Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top