Results 1 to 5 of 5
  1. #1
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default How to add mouse clicked listener on rows of a jtable

    Hi,

    I have a jtable and I want to have a mouse clicked listner on the rows of the table.
    I am using netbeans.
    If I click on the design view and on the table name ,I am unable to add events .Please let me know how can I add a mouse listener.If i try to do it via the code the initcomponents methods is in blue and I cannot change it.

    Please help.

    Thanks,

  2. #2
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    The easiest way to do this is add a mouse listener to the table,
    then check, if the user clicked, which column the user clicked on.

    hannes

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There's probably no need to add a MouseListener to a JTable as you can get a JTable's ListSelectionModel by calling getListSelectionModel() on it, and you can then add a ListSelectionListener to this model to achieve what you are trying to do.

  4. #4
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default

    Thanks for the reply.

    It would be of help if you could explain how can I add an event using netbeans.
    I right click on the table name under the design view but there is no option for add new event .Its only showing the events already there on that table.
    How to do it via code ? The code where I have to add is blue and it cannot be edited.


    Thanks,

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I don't use NetBeans code-generation to create my Swing apps, and I recommend that you don't either til you're comfortable creating Swing apps by hand. The Swing tutorials can show you the way: Using Swing Components

Similar Threads

  1. Jtable rows
    By riddhishah28 in forum AWT / Swing
    Replies: 3
    Last Post: 02-18-2011, 06:24 AM
  2. X & Y of the following event "Mouse clicked"
    By jack DANIEL's in forum Advanced Java
    Replies: 2
    Last Post: 10-12-2010, 03:15 PM
  3. Replies: 2
    Last Post: 03-01-2010, 03:19 PM
  4. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 04:34 AM
  5. Replies: 6
    Last Post: 03-17-2009, 02:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •