• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable cell selection

 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to fire mouse listener when we select a particular cell from JTable ?

table.isCellSelected(6,0);
table.isCellEditable(6,0);

are not working
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DefaultTableModel dmodel = new DefaultTableModel(rowData,columnNames);
resultTable = new JTable(dmodel);
resultTable.setRowHeight(40);
resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
resultTable.getAutoCreateColumnsFromModel();
// resultTable.getTableHeader().setResizingAllowed(false);
resultTable.setPreferredScrollableViewportSize(resultTable.getPreferredSize());
resultTable.getColumnModel().getColumn(6).setCellRenderer(new HyperTextRenderer());
resultTable.getColumnModel().getColumn(6).setPreferredWidth(130);
resultTable.getColumnModel().getColumn(5).setPreferredWidth(100);
JScrollPane spane = new JScrollPane(resultTable);
replacePnl.add(sub1,BorderLayout.NORTH);
//replacePnl.add(solCompatibilitySearch,BorderLayout.NORTH);
//replacePnl.add(searched,BorderLayout.NORTH);
replacePnl.add(spane,BorderLayout.WEST);
In the above code 6 th column cell having some labeled hypertext text and click on that particular cell i want to open some other dialog box , can you please help me ...
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JTable itself is not aware of any selection changes nor data for that matter. It relies on XXXModels. (In case you dont know, google for MVC architecture)

So what you need to do is:

1)Get the table's selection model (JTable#getSelectionModel)
2)Add a selection listener to the selection model (ListSelectionModel#addListSelectionListener)
3)The listener will tell you when the table selection changes. Then you can make calls to the table to figure out which row/column is currently selected and process it accordingly.
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!