• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JTable editing on mouse click

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a custom renderer/editor that uses a JTextField. I click w/ the mouse on a cell...the cell is "selected" but no caret is visible. I enter text and it appears at the end of the String, but still no caret.
What I want is to click on a cell and the cell become editable w/ the caret positioned where the mouse click occured.
Suggestions?
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default, the cursor will appear when the cell is double clicked.
I don't know, if it would help to set the DefaultCellEditor.setClickCountToStart() to 1. Of course, that will work only in the case you are using the DefaultCellEditor or a subclass of it.
Another possibility might be, to set the caret of the Editor (as a subclass of JTextField/JTextComponent) explicitely). there most likely is some method in the API that does this. If not in the JTextComponent hierarchy than in Document or its subclasses (something like setCaret(int position)).
Chantal
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread is a couple of years old but I've run into exactly the same problem. I wondered if anyone has any further suggestions.
 
Keith L
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, the code below does what I want. I'd have thought there would be some way form me to call setClickCountToStart() on the system-supplied DefaultCellEditor rather than creating a new one, but I couldn't find it.


TableColumn col = envtable.getColumnModel().getColumn(1);
DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField());
singleclick.setClickCountToStart(1);
col.setCellEditor (singleclick);
 
reply
    Bookmark Topic Watch Topic
  • New Topic