JFormattedTextField: isEditValid() : JFormattedTextField « javax.swing « Java by API






JFormattedTextField: isEditValid()

  
import java.awt.GridLayout;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MainClass {

  public static void main(String argv[]) {

    java.net.URL u = null;
    try {
      u = new java.net.URL("http://www.java2s.com/");
    } catch (java.net.MalformedURLException ignored) {
    }

    JFormattedTextField ftf1 = new JFormattedTextField(u);
    JFormattedTextField ftf2 = new JFormattedTextField(u);

    ftf2.setInputVerifier(new InputVerifier() {
      public boolean verify(JComponent input) {
        if (!(input instanceof JFormattedTextField))
          return true;
        return ((JFormattedTextField) input).isEditValid();
      }
    });

    JPanel p = new JPanel(new GridLayout(0, 2, 3, 8));
    p.add(new JLabel("plain JFormattedTextField:"));
    p.add(ftf1);
    p.add(new JLabel("FTF with InputVerifier:"));
    p.add(ftf2);
    p.add(new JLabel("plain JTextField:"));
    p.add(new JTextField(u.toString()));

    JFrame f = new JFrame("MainClass");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JLabel("Try to delete the colon in each field."), "North");
    f.getContentPane().add(p, "Center");
    f.pack();
    f.setVisible(true);
  }
}

           
         
    
  








Related examples in the same category

1.new JFormattedTextField(Format format)
2.new JFormattedTextField(Formatter formatter)
3.new JFormattedTextField(AbstractFormatterFactory factory, Object currentValue)
4.new JFormattedTextField(Object value)
5.new JFormattedTextField(new MaskFormatter('(###)###-####'))
6.new JFormattedTextField(new DecimalFormat('###,###'))
7.new JFormattedTextField(new SimpleDateFormat('MM/dd/yy'))
8.JFormattedTextField: addActionListener(ActionListener l)
9.JFormattedTextField: commitEdit()
10.JFormattedTextField: getFormatterFactory()
11.JFormattedTextField: getValue()
12.JFormattedTextField: setColumns(int columns)
13.JFormattedTextField: setFont(Font f)
14.JFormattedTextField: setFormatterFactory(AbstractFormatterFactory tf)
15.JFormattedTextField: setInputVerifier(InputVerifier inputVerifier)
16.JFormattedTextField: setValue(Object value)
17.JFormattedTextField deals with URL