Results 1 to 3 of 3
Thread: Multiple selection on JTable
- 01-30-2009, 03:25 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
[SOLVED] Multiple selection on JTable & store datas into an array
Hello friends!
Can anybody show me any method for selecting multiple values (rows) from a JTable?
I mean, i have a JTable; the user selects 2 or more rows; how can i pass these values into an array, for example?
I know that getSelectedRows returns the index of the selected rows, and that's fine, but i need to store the datas which are in the rows into an array.
Thanks so much!Last edited by hendrix79; 01-30-2009 at 05:11 PM. Reason: Solved, thanks alot.
- 01-30-2009, 05:10 PM #2
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
Hopefully i solved it.
This is how:
I hope this could help someone with my same problem.Java Code:private void tabellaProgrammiMouseClicked(MouseEvent evt) { r = tabellaProgrammi.getSelectedRow(); if (r==-1) { } else { java.util.List<String> elenco = new ArrayList<String>(); ind = tabellaProgrammi.getSelectedRows(); int z =ind.length; String[] listaId = new String[z+1]; for (int i=0; i<z; i++) { elenco.add((String) tabellaProgrammi.getValueAt(ind[i], 0)); } listaId = (String[])elenco.toArray(new String[elenco.size()]); } }
Thanks :)
- 01-30-2009, 06:11 PM #3
My only comment would be:
It's not a good programming practice to leave empty "then" statements.Java Code:if ([B][COLOR="Blue"]!(r==-1)[/COLOR][/B]) { java.util.List<String> elenco = new ArrayList<String>(); ind = tabellaProgrammi.getSelectedRows(); int z =ind.length; String[] listaId = new String[z+1]; for (int i=0; i<z; i++) { elenco.add((String) tabellaProgrammi.getValueAt(ind[i], 0)); } listaId = (String[])elenco.toArray(new String[elenco.size()]); }
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
How to sort a JTable for multiple columns?
By BLR in forum Advanced JavaReplies: 2Last Post: 03-16-2009, 10:41 AM -
JTable Combo Box Row Selection Problem
By hemanthjava in forum AWT / SwingReplies: 2Last Post: 12-18-2008, 07:31 AM -
List Selection
By Sarinam in forum AWT / SwingReplies: 2Last Post: 07-14-2008, 06:16 AM -
Jtable duplicates through Hashtable (JTable condition problem) my assignment plz help
By salmanpirzada1 in forum Advanced JavaReplies: 2Last Post: 05-15-2008, 10:15 AM -
Code for selection
By kneekow in forum EclipseReplies: 0Last Post: 02-01-2008, 03:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks