• 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

Create JTable custom editor to validate againts string data type

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to implement the IntegerEditor class at the swing java tutorial; but instead of an integer, I would like to validate against a string. In other words, I want to make sure that the user does not input an integer but a string. I cannot figure out how to chack for string input and the code does not allow me to edit at all. Any ideas?

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe something like:

 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not tried the mask code for the string case yet; but I am working on a date format efitor and there is a problem. The method getCellEditorValue() does not capture the value; the editor or component does not seem to work, therefore the method isEditValid always returns false, and I always get the pup up error message.

Could you please go over my code? Every thing else works fine.

Thank you,

Giuseppa


 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not understand how to use the code below. Could you please insert it in the program I sent?

Thank you Giuseppa

 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The codes show how you mght add this editor to the first column, however the code doesn't work very well so I guess I would forget about using it.

The rest of the code may be more helpful. It shows my example of a custom editor which is then used by the remaining columns. In this case it just verifies that you entered "5 characters. You should be able to customize the 5 character edit to do whatever you want.

 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much! This is great. I can customize it for text in general; but I am going to try to customize it for dates as well

Giuseppa
 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The editor works very well when I use it in the class that you designed; but when I use it inside my own class it just turns the string cells completelly uneditable. Could you please take a look at my code? I t might have to do with the fact that tha JTable class is a separate class thate xtneds ABstractTableModel; while the editor is in the TableEditor class.
dbtable = new DatabaseT();
table = new JTable(dbtable);


Thank you;

Giuseppa

 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a custom TableModel then you need to overreid the isCellEditable(...) method to return true for the columns you want to be editable.
 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is my class. I am overriding isCellEditable(int row, int col); but still does not work. Ihave no idea of what mght be wrong.

Giuseppa

 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The editor works for strings very well. The problem is that is also works for dates and any time that I want to edit a date is imposses me the 5 characters string. This is how I chose the columns to be edited by the editor. Is there another way to chose the columns for which the editor should be installed?

Thank you,

Giuseppa

 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why do you keep posting that code. I told you it doesn't work.

Is there another way to chose the columns for which the editor should be installed?



My example already showed you how to add an editor for a class or a column. That is why I posted a working example!

If you want to assign an editor to all columns with a specific class you use:



If you want to assign an editor to a specific column you use:



 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I do not undertand what does not work
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic