wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Create JTable custom editor to validate againts string data type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Create JTable custom editor to validate againts string data type" Watch "Create JTable custom editor to validate againts string data type" New topic
Author

Create JTable custom editor to validate againts string data type

Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jun 13, 2009
Posts: 2152
    
    7
Maybe something like:

Giuseppa Cefalu
Ranch Hand

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jun 13, 2009
Posts: 2152
    
    7
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

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jun 13, 2009
Posts: 2152
    
    7
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

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jul 15, 2011
Posts: 121
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

Joined: Jun 13, 2009
Posts: 2152
    
    7


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

Joined: Jul 15, 2011
Posts: 121

I do not undertand what does not work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create JTable custom editor to validate againts string data type
 
Similar Threads
maxlength for customer id column
JTable date edit problem
MaskFormatter in JTable
JDateChooser in JTable
BigDecimalEditor ignores 0