Results 1 to 5 of 5
- 01-15-2011, 10:33 AM #1
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
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?
- 01-15-2011, 04:32 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
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.
- 01-16-2011, 12:23 AM #3
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
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
- 01-16-2011, 01:07 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
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.
- 01-16-2011, 05:22 AM #5
Senior Member
- Join Date
- Feb 2009
- Posts
- 117
- Rep Power
- 0
Similar Threads
-
set gender and selected combobox value
By wynects in forum Java ServletReplies: 0Last Post: 12-21-2010, 06:03 AM -
confusing output of a selected cell in a JTable
By bigj in forum New To JavaReplies: 6Last Post: 01-30-2010, 02:55 PM -
JButton selected
By sky in forum AWT / SwingReplies: 6Last Post: 12-05-2009, 09:36 PM -
JTable Gridline in selected row
By arubin in forum AWT / SwingReplies: 11Last Post: 11-24-2009, 07:05 PM -
JTable problem with getting ROW selected
By nadia in forum Advanced JavaReplies: 2Last Post: 01-13-2009, 05:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks