Results 1 to 5 of 5
  1. #1
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default how to get the currently selected row fo a jtable?

    hi, I was trying to use a jtable somehow as a trigger for other events like if a row gets selected another window would pop up.

    tried to give the table itself the mousepressed event using eclipse but when I click it, it does nothing.

    I was wondering how can I get the selected row on a jtable?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Without any code snippet its a guessing game as to why 'it does nothing'. Recommend using a ListSelectionListener (see How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)) to listen for selections, unless you want the behavior to be defined by a mouse click. To get the selected row(s), call getSelectedRow() or getSelectedRows()
    Last edited by doWhile; 01-15-2011 at 04:38 PM.

  3. #3
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    hey, thanks for the advice.. was able to use the tutorial you recommended. thanks, and one more question

    when I use the List Selection Listener it triggers twice. when I click the items on the table it triggers twice. but when I just press the mouse key it will trigger one time and when I release it , it will trigger again. can you give me any ideas so that the listener would trigger once?

    regards

    simon

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    The ListSelectionListener may appear to be fired 'twice', but its can be fired for selection changes (even when values are changing). Try filtering out selection only when they are not adjusting
    Java Code:
    public void valueChanged(ListSelectionEvent event){
        if ( !event.getValueIsAdjusting() ){
    
        }
    }
    Last edited by doWhile; 01-16-2011 at 01:09 AM.

  5. #5
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

Similar Threads

  1. set gender and selected combobox value
    By wynects in forum Java Servlet
    Replies: 0
    Last Post: 12-21-2010, 06:03 AM
  2. Replies: 6
    Last Post: 01-30-2010, 02:55 PM
  3. JButton selected
    By sky in forum AWT / Swing
    Replies: 6
    Last Post: 12-05-2009, 09:36 PM
  4. JTable Gridline in selected row
    By arubin in forum AWT / Swing
    Replies: 11
    Last Post: 11-24-2009, 07:05 PM
  5. JTable problem with getting ROW selected
    By nadia in forum Advanced Java
    Replies: 2
    Last Post: 01-13-2009, 05:57 PM

Posting Permissions

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