문제

wondering how I would get around populating a two-dimensional array after the user manually selects data from a JTable i.e. if you select two cells from the JTable which are (Football, Rugby) then they will be added to the new array the two array should populate in relation to [row][column]. I am asking this so I'm able to pass this array through to another class which will create visualizations. The code for my ListSelectionModel is:

http://pastebin.com/eNYz3us2

If i were to highlight the two cells (Football, Rugby) it would print out to the command line "FootballRugby" so just need to store this in the array!

Thanks for any help :)

도움이 되었습니까?

해결책

This will give you the selected row and the selected column from the JTable. If no cell is selected then getSelectedXXX method will return -1.

table.getSelectedColumn(); // Gives the selected column.
table.getSelectedRow();   // Gives the selected row.

After getting the row and the column call getValueAt method to get the value at that position.

Now you have the required data with you and you can store it in the array and pass it to another class for visualization.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top