aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Row validation in a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Row validation in a table" Watch "Row validation in a table" New topic
Author

Row validation in a table

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I want to validate the row when the user leaves the row. I have implemented a ListSelectionListener, but from there it doesn't seem to give me what I want.

Here is the code that is fired when the row changes



e is the ListSelectionEvent.

So I am adding rows to the JTable. I have a button outside the JTable for adding rows, so it is when I click the button that it will add a row and put the cursor into the first cell of that row. Each time I add a row it fires off the code twice. I added two rows, here is the output



So I think the second one is row number of the added row. The first two should not even appear as it added a row, which changes the row selected from -1 to 0. But it should have fired when adding the second row since I am "leaving" the first row.

Now when I am in the table and use the up and down arrows it only first once, which is good, but I am trying to get the exact row number that I just left, which it isn't because the Event has first and last index, but not the row that was "last edited"

Any help that can allow me to validate a row when you leave a row, whether you stay in the JTable or not.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Thanks Craig. Great code.

In you example it looks like the validation is occured per cell rather than when leaving a row. Is this true? I want to do validation after leaving the row. The reason why is that the validation is just that the mandatory fields are filled in, not the values themselves.

And my last question is this



the row, is that the new row selected, or the one you just left?

Thanks for your help.

Mark
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
...validation is occured per cell rather than when leaving a row.
Yes, I set this up to validate each cell.
To validate a row for input fields you might consider making a one–row JTable as the row component and adding it to the table. I see that JTable supports InputVerifier which you might be able to use to verify the row table before focus is surrendered.

...is that the new row selected, or the one you just left?
It's the new row selected.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Thanks Craig.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Row validation in a table