• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Row validation in a table

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Craig.

Mark
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic