How to set and highlight text in JTable cell on selection and/or invoke cell editor directly.

Discussion in 'Java' started by news.rcn.com, Jul 12, 2004.

  1. news.rcn.com

    news.rcn.com Guest

    I have a JTable whose cells display values derived from the data in the
    TableModel (rather than the the data itself.)

    When a cell is selected (by mouse or keyboard navigation) I need to
    1) show the raw data from the table model (not the derived data)
    2) highlight it to show it will be replaced after editing.
    This needs to be done before the user types into the cell.

    I can't figure out how to catch an event when a table cell is selected. My
    best guess is to is overide the 'isCellEditable' in the table model and try
    to get the cell renderer, then get the Component that draws it.
    and load the raw data and select it. However, I could not get this to work.

    Alternatively, if I could the cell editor directly when the table cell gets
    selected, I could load the raw data in there and let the user have her way
    with it. Can I do this? It seems that nobody cares about the editor until
    the table cell gets a keystroke typed into it; then the editor UI takes over
    the table cell real estate (from the renderer).

    I'd appreciate any help or suggestions. Thanks in advance.

    jim cant
    news.rcn.com, Jul 12, 2004
    #1
    1. Advertising

  2. news.rcn.com

    Chris Smith Guest

    news.rcn.com wrote:
    > I have a JTable whose cells display values derived from the data in the
    > TableModel (rather than the the data itself.)
    >
    > When a cell is selected (by mouse or keyboard navigation) I need to
    > 1) show the raw data from the table model (not the derived data)
    > 2) highlight it to show it will be replaced after editing.
    > This needs to be done before the user types into the cell.
    >
    > I can't figure out how to catch an event when a table cell is selected. My
    > best guess is to is overide the 'isCellEditable' in the table model and try
    > to get the cell renderer, then get the Component that draws it.
    > and load the raw data and select it. However, I could not get this to work.


    Instead of this, why not just implement the cell renderer to return the
    desired look for a selected component? The cell will be re-rendered
    when it is selected, after all.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Jul 12, 2004
    #2
    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,223
  2. Tivo Escobar
    Replies:
    1
    Views:
    7,268
    manusa
    Apr 12, 2007
  3. Simon Niederberger
    Replies:
    2
    Views:
    16,435
    Christian Kaufhold
    Jan 7, 2005
  4. apattin
    Replies:
    2
    Views:
    2,716
    alejandrina
    Apr 28, 2006
  5. Replies:
    2
    Views:
    173
Loading...

Share This Page