Right click on Cell of JTable


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Right click on Cell of JTable

  1. #1
    Join Date
    Aug 2004
    Posts
    7

    Unhappy Right click on Cell of JTable

    Hi, Iím trying to catch a right click event mouse on a javax.swing.DefaultCellEditor. editorComponent.

    The JTable active the edition with a left click of mouse and I get that event without problem, but I donít now how trigger the edition of a cell with a right click.

    I need the right click because the component that edit the cell value work with that mouse event too.

    How can I do this?

    PD: Excuse my english.
    3-)

  2. #2
    Join Date
    Jun 2004
    Posts
    199
    How are doing it now? The mouse event is general so you should be getting it either way.

    http://java.sun.com/j2se/1.4.2/docs/...ouseEvent.html

  3. #3
    Join Date
    Aug 2004
    Posts
    7

    Thumbs up

    I override the processMouseEvent of my javax.swing.DefaultCellEditor.editorComponent but the JTable only pass mouse movements or left buttons events, never the BUTTON3 events.

    Now I'm trying to override the processMouseEvent of JTable, capture de right click event and call JTable.editCellAt(row, col, MouseEvent).

    This work while the cell is selected, but I canít still make a selection of the cell with a right click. First I have to select the cell with a left click and then use the right click to edit the cell.

    Thanks a lot for your time.

  4. #4
    Join Date
    Jun 2004
    Posts
    199
    You shouldn't be overriding those methods. You should be adding event listeners.

    Also, trying use a custom renderer (like a JLabel) instead of the default. I'm pretty sure I've done it before.

    The thing is, with JTable, you should have something "selected" before you attempt to do an operation. So select with left mouse and right click to popup menu is normal behaviour.

  5. #5
    Join Date
    Aug 2004
    Posts
    7

    Lightbulb

    I see my problem now and do this with your advice:

    class MyEditor(MyEditorControl ec) extends DefaultCellEditor {

    public MyEditor(MyEditorControl ec) {
    super(new JCheckBox()); //the constructor always
    //expects a check box, combo box,
    //or text field.
    editorComponent = ec;
    setClickCountToStart(1);

    ec.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    //ÖMake edition job
    }
    });
    }
    }

    Now the code is clearer. You are right when you say that is normal behavior to left click on cell for activate edition and then use the right click. Thatís the standard manner of work of grid controls in Windows and Unix and Iím going to let JTable do his job.

    Thanks very much, I appreciate your help.
    3-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center