JTable with row selection, but no cell selection

Discussion in 'Java' started by Simon Niederberger, Jan 4, 2005.

  1. 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
    Simon Niederberger, Jan 4, 2005
    #1
    1. Advertising

  2. >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);

    --
    Andrey Kuznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
    Andrey Kuznetsov, Jan 5, 2005
    #2
    1. Advertising

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

    Simon Niederberger <> wrote:

    > 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
    Christian Kaufhold, Jan 7, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don
    Replies:
    4
    Views:
    8,224
  2. Tivo Escobar
    Replies:
    1
    Views:
    7,269
    manusa
    Apr 12, 2007
  3. news.rcn.com
    Replies:
    1
    Views:
    9,630
    Chris Smith
    Jul 12, 2004
  4. apattin
    Replies:
    2
    Views:
    2,716
    alejandrina
    Apr 28, 2006
  5. D
    Replies:
    0
    Views:
    197
Loading...

Share This Page