Package javax.swing

Examples of javax.swing.InputVerifier


//        }
        /*
         * Set an input verifier to prevent the cell losing focus when the value
         * is invalid
         */
        textField.setInputVerifier(new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                JFormattedTextField ftf = (JFormattedTextField) input;
                return ftf.isEditValid();
            }
View Full Code Here


            Utils.showException(GitblitAuthority.this, x);
          }
          certificateConfig = NewCertificateConfig.KEY.parse(config);
          certificateConfig.update(metadata);
        }
        InputVerifier verifier = new InputVerifier() {
          @Override
          public boolean verify(JComponent comp) {
            boolean returnValue;
            JTextField textField = (JTextField) comp;
            try {
View Full Code Here

            }

        });

        /* get an input verifier for mac addresses */
        InputVerifier macInputVerifier = new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try{
                    @SuppressWarnings("unused")
                    MACAddress addr = new MACAddress(((JTextField)input).getText());
                } catch (Exception e) {
                    return false;
                }
                return true;
            }

            /*
             * (non-Javadoc)
             * @see javax.swing.InputVerifier#shouldYieldFocus(javax.swing.JComponent)
             */
            public boolean shouldYieldFocus(JComponent input){
                if(!verify(input)){
                    ((JTextField)input).setBackground(Color.RED);
                    return false;
                } else {
                    ((JTextField)input).setBackground(Color.WHITE);
                    return true;
                }
            }
        };

        /* set the input verifier for the MAC text fields */
        this.macDestAddrTextField.setInputVerifier(macInputVerifier);

        /* write destination MAC address to the hardware */
        this.macDestAddrTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateDestMac();
            }
        });

        /* set the input verifier for the source MAC address */
        this.macSrcAddrTextField.setInputVerifier(macInputVerifier);

        /* write the source mac address to the hardware */
        this.macSrcAddrTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateSrcMac();
            }
        });

        /* get an input verifier for integers */
        InputVerifier integerInputVerifier = new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try{
                    Integer.parseInt(((JTextField)input).getText());
                } catch (Exception e) {
                    return false;
                }
                return true;
            }

            /*
             * (non-Javadoc)
             * @see javax.swing.InputVerifier#shouldYieldFocus(javax.swing.JComponent)
             */
            public boolean shouldYieldFocus(JComponent input){
                if(!verify(input)){
                    ((JTextField)input).setBackground(Color.RED);
                    return false;
                } else {
                    ((JTextField)input).setBackground(Color.WHITE);
                    return true;
                }
            }
        };

        /* set the graph num points input verifier */
        this.graphSizeTextField.setInputVerifier(integerInputVerifier);

        /* add action listener to set graph size */
        this.graphSizeTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateGraphSizes();
            }
        });

        /* Set udp destination port text field input verifier */
        this.udpDestPortTextField.setInputVerifier(integerInputVerifier);

        /* set the action listener */
        this.udpDestPortTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateUdpDestField();
            }
        });

        /* Set udp Source port text field input verifier */
        this.udpSrcPortTextField.setInputVerifier(integerInputVerifier);

        /* set the action listener */
        this.udpSrcPortTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateUdpSrcField();
            }
        });

        /* create an IP address input verifier */
        InputVerifier ipInputVerifier = new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try{
                    new IPAddress(((JTextField)input).getText());
                } catch (Exception e) {
View Full Code Here

     * integer input.
     * @return JTextField
     */
    public static JTextField createIntegerTextField() {
        JTextField textField = new NumericTextField();
        textField.setInputVerifier(new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try {
                    Integer.parseInt(((JTextField) input).getText());
                    return true;
View Full Code Here

     * or decimal input.
     * @return JTextField
     */
    public static JTextField createDecimalTextField() {
        JTextField textField = new NumericTextField();
        textField.setInputVerifier(new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try {
                    Double.parseDouble(((JTextField) input).getText());
                    return true;
View Full Code Here

                    updateModel();
                }
            }
        });

        textComponent.setInputVerifier(new InputVerifier() {

            public boolean verify(JComponent c) {
                updateModel();
                // release focus after coloring the field...
                return true;
View Full Code Here

        this.undoableListener = new JTextFieldUndoListener(this);
        this.textComponent.getDocument().addUndoableEditListener(this.undoableListener);

        if (checkOnFocusLost) {
            textComponent.setInputVerifier(new InputVerifier() {

                public boolean verify(JComponent c) {
                    updateModel();
                    // release focus after coloring the field...
                    return true;
View Full Code Here

      comp.setBackground(Color.red);
      //Ugly work-around: with 1.4 stackoverflow will occur when trying to show
      //the dialog as this will try to get focus from the component and this
      //method will be called again and so on. Thus we temporarily deactivate
      //the input verifier here:
      InputVerifier v = comp.getInputVerifier();
      comp.setInputVerifier(null);
      JOptionPane.showMessageDialog(comp, SequenceTextField.ILLEGAL_INPUT_MESSAGE, SequenceTextField.ILLEGAL_INPUT_TITLE,
                                    JOptionPane.ERROR_MESSAGE);
      comp.setInputVerifier(v);
      comp.requestFocus();
View Full Code Here

  /** A generic listener class that will validate on an event */
  public static class VerifierListener implements ActionListener {
      public void actionPerformed(ActionEvent e){
        JComponent c = (JComponent)e.getSource();
        InputVerifier v = c.getInputVerifier();
        if (v != null) // on init, it is null
          v.verify(c);
      }
View Full Code Here

/**
* On pressing enter key, check any unvalidated component
*/ 
  public void onOk() {
    if (dirtyComponent != null) {
      InputVerifier verifier = dirtyComponent.getInputVerifier();
      if (!verifier.shouldYieldFocus(dirtyComponent))
        return;
    }
    super.onOk();
  }
View Full Code Here

TOP

Related Classes of javax.swing.InputVerifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.