• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to get the selected row in a list  RSS feed

 
selva kum
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am displaying a list(set of rows) using Swings and on mouse click I want to show detailed message of the selected row. for this i have written the below code(pseudo code given below) and getting a compilation issue. please let me know the suitable way to get the selected rows.

pseudo code:
QueryTableModel qtm = new QueryTableModel();
JTable table = new JTable(qtm);

JScrollPane scrollpane = new JScrollPane(table);

table.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
System.out.println("value:" + table.getSelectedRow());
}});

compilation issue:
cannot refer to a non-final variable table inside an inner class defined in a different method
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"cannot refer to a non-final variable table inside an inner class defined in a different method"

=> "final JTable..."
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot refer to a non-final variable table inside an inner class defined in a different method

there are two options:

- create JTable as local variable

- final JTable table = new JTable(qtm);


table.addMouseListener(new MouseAdapter(){

- use ListSelectionListener

- maybe you would need change selection model to SINGLE

- read Oracle tutorials for (both a.m. point) working code example
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!