Skip to main content

Cant get an InputVerifier's verify function to be called from a JTable cell

No replies
elbakri
Offline
Joined: 2010-08-08

I'm pretty new to all of this so any help would be greatful. Below is simple app where I'm building a default table and trying to verify user input on column(0). I try to verify user input by connecting an IDateVerifier which is sbuclassed from nputVerifiier. For simplicity purposes the verify() method of the DateVerifier class just prints a message when called. Why doens't this ever get called? What am I doing wrong or not doing? Thanks in advance.

man code :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.table.*;
public class TableEdit extends JFrame
{
TableEdit()
{
JTable table = new JTable(5,5);
JTextField datetf = new JTextField();
datetf.setInputVerifier(new DateVerifier());
table.setPreferredScrollableViewportSize(table.getPreferredSize());
TableColumn col = table.getColumnModel().getColumn(0);
col.setCellEditor(new DefaultCellEditor(datetf));
JScrollPane scrollpane = new JScrollPane(table);
getContentPane().add(scrollpane);
}
public static void main(String [] args)
{
JFrame frame = new TableEdit();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);
}

}

// DateVerifier class
import javax.swing.*;
import javax.swing.JComponent;
import javax.swing.JTextField;
public class DateVerifier extends InputVerifier
{
public DateVerifier()
{
super();
System.out.println("creating DateVerifier");
}

public boolean verify (JComponent component)
{
System.out.println("verify.....");
JTextField tf = (JTextField)component;
String s = tf.getText();
// if(s==null)
// return true;
// else
// return JulianDate.isValidDate(s);
return true;
}

}