Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2004

Tip: Looking for answers? Try searching our database.

JFormatterTextField.isEditValid() not being called?

Thread view: 
Boris Pelakh - 15 Nov 2004 15:32 GMT
I have a table with a text column. I would like to ensure that the
values in that column remain unique when edited. I have created the
following class

class NameTextField extends JFormattedTextField {
 Set currentNames = null;
   
 public void setCurrentNames(Set currentNames) {
   this.currentNames = currentNames;
 }

 public boolean isEditValid() {
   String val = getFormatter().toString();
   System.out.println("isEditValid called with '"+val+"'");
   if (val == null || val.length() == 0 ||
       currentNames.contains(val)) {
     return false;
   }
   else {
     return super.isEditValid();
   }
 }
}

I then set the CellEditor for the column with

TableColumn nameColumn =
getColumnModel().getColumn(AttributeTableModel.NAME_COL);
text = new NameTextField();
nameColumn.setCellEditor(new DefaultCellEditor(text));

I expect isEditValid() to be called each time I press 'Enter' after
editing the field. I would also expect that if I returned false, the
field would retain focus and force the user to correct the problem.

What I get is the method is not getting called at all. What am I doing
wrong? Do I need to define a Formatter? FormatterFactory?
Kleopatra - 16 Nov 2004 10:00 GMT
> I have a table with a text column. I would like to ensure that the
> values in that column remain unique when edited. I have created the
> following class
>
> class NameTextField extends JFormattedTextField {

[...]

> I then set the CellEditor for the column with
>
[quoted text clipped - 7 lines]
> What I get is the method is not getting called at all. What am I doing
> wrong? Do I need to define a Formatter? FormatterFactory?

DefaultCellEditor does nothing to validate any input before stopping
edits - in your case that's more or less okay, because it need not
expect that the given textField actually is a JFormattedTextField which
has a special method to do so - but it not even consults any
InputVerifiers set to the editing components.

What you need to do is to provide a custom CellEditor which calls
isEditValid in editor.stopCellEditing(). There's an example in Sun's
Swing tutorial (How to use Tables)  which might be helpful.

Jeanette


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.