Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable Listener onClick!

Status
Not open for further replies.

FOR111

Programmer
Sep 29, 2005
103
MT
Hi all,

I'm currently using the ListSelectionModel Event listener but this tends to work after the row has been selected. I would like to find a listener which works somewhat like 'Onclick' of a row!?

Any help?

Thanks
Nick
 
ps. I currently have this going on:

Code:
 ListSelectionModel rowSM = table.getSelectionModel();

	//Listener for row change;
    
	rowSM.addListSelectionListener(new ListSelectionListener() {
			    public void valueChanged(ListSelectionEvent e) {
		
			        if (e.getValueIsAdjusting()) return;
			        
			        table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
			
			        ListSelectionModel lsm =
			            (ListSelectionModel)e.getSource();
			        if (lsm.isSelectionEmpty()) {
			 
			        } else {
			            
			        	int selectedRow = lsm.getMinSelectionIndex();
			        	
			            Boolean theBox = (Boolean)table.getValueAt(selectedRow, 0);
			            JProgressBar theBar = (JProgressBar)table.getValueAt(selectedRow, 3);
			            
			            if (theBox == true)
			            {
			            	theBar.setValue((theBar.getValue()+1));
			            }
			            else
			            {
			            	theBar.setValue((theBar.getValue()-1));
			            }
			            theBar.setString(String.valueOf(theBar.getValue()).concat("%"));
			            
			        }
			    }
			});
 
Off the top of my head, calling:

table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

inside the ValueChanged method of the listener looks dangerous. Does the row stay selected? I'd do that in the initalization of the table, not inside ValueChanged.

On perusing I found this:

valueChanged(ListSelectionEvent) Called when the selection in the listened-to component is changing, as well as just after the selection has changed.

So I'd think you'd need to do your processing when e.getValueIsAdjusting() is true to catch it "onClick."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top