File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create JTable custom editor to validate againts string data type

 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • 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?

 
Rob Camick
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe something like:

 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I do not undertand what does not work
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic