Cancel InputVerifier

Hello,
I have a dialog with a JTextField on it. With an inputverifier class, I validate the content of the textfield. When the content is invalid I show a message ( with JOptionpane )
The problem is if I enter an invalid value in the text field and I click the cancel button I get the message that the input is wrong. Is there a way to prevent the validation through the Inputverifier class when cancel is pressed?
Thanks a lot

This is my code:
public class Test extends JDialog implements ActionListener
    JTextField txt = new JTextField(50);
    private JButton okBtn;
    private JButton cancelBtn;
    private static Test test;
    public static void main(String[] args)
        test = new Test(null, "test", false);
        test.pack();
        test.setVisible(true);
    public Test(Frame owner, String title, boolean modal)
        super(owner, title, modal);
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        txt.setInputVerifier(new PassVerifier());
        panel.add(txt, BorderLayout.NORTH);
        JPanel buttonPanel = new JPanel();
        okBtn = new JButton("Ok");
        okBtn.addActionListener(this);
        cancelBtn = new JButton("Cancel");
        cancelBtn.addActionListener(this);
        buttonPanel.setLayout(new FlowLayout());
        buttonPanel.add(cancelBtn);
        buttonPanel.add(okBtn);
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        c.add(panel, BorderLayout.NORTH);
        c.add(buttonPanel, BorderLayout.SOUTH);
        addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent e)
                System.exit(0);
            public void windowClosed(WindowEvent e)
                System.exit(0);
    public void actionPerformed(ActionEvent e)
        if (e.getSource() == cancelBtn)
            System.exit(0);
    class PassVerifier extends InputVerifier
        public boolean verify(JComponent input)
            JTextField tf = (JTextField) input;
            String pass = tf.getText();
            if (pass.equals("pass"))
                return true;
            else
                if ( pass.length() > 0)
                    JOptionPane.showMessageDialog(null, "Error", "Error", JOptionPane.ERROR_MESSAGE);
                    return false;
                else
                    return true;
}

Similar Messages

  • InputVerifier + Cancel Button

    I've got a application with a JTextField and 2 Buttons (OK and Cancel)
    I'd like the InputVerifier doesn't work when the user click on Cancel button.
    What should I do ?
    Into class ImputVerifier there's how to know what button was clicked ?

    tf1 = new JTextField();
    bcancel = new JButton();
    bok = new JButton();
    tf1.setInputVerifier(new MyVerifier( tf1 ));
    bcancel.setText( "Cancel" );
    bok.setText( "OK" );
    class MyVerifier extends InputVerifier {
    JTextButton faux ;
    public MyVerifier( JTextButton aux ){
    super();
    faux = aux;
    public boolean verify(JComponent field){
    // It must return true when the Cancel button is cliked
    // but, I don't know if the cancel button was clicked
    // there are anyway to check what button was clicked ?
    if (!faux.getText().equals( "pass" ) {
    return false;
    return true;

  • InputVerifer unable to exit with cancel button.

    Just playing with the verifier and notice that I am unable to "cancel" when I failed the validation. I understand that I can not conintue to next field, but if I failed but how come I can't cancel out of the form? I could exit if use the [x] on the upper right side. which uses the WindowAdapter.
    Any idea on how I can permit my cancel button to work under this situation also?
    Here is my sample code. The basic code I got it from http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/InputVerifier.html
    modified for my own test.
    package verifier;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class VerifierTest extends JFrame {
        public VerifierTest() {
            JTextField tf1 = new JTextField ();
            getContentPane().add (tf1, BorderLayout.NORTH);
            tf1.setInputVerifier(new PassVerifier());
            JTextField tf2 = new JTextField ("next field");
            getContentPane().add (tf2, BorderLayout.CENTER);
              JButton buttonCancel = new JButton("cancel");
              buttonCancel.addActionListener(new CancelListener());
              getContentPane().add(buttonCancel,BorderLayout.SOUTH);     
            WindowListener l = new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                     System.out.println(" win closing");
                    dispose();
            addWindowListener(l);
        class PassVerifier extends InputVerifier {
            public boolean verify(JComponent input) {
                JTextField tf = (JTextField) input;
                  if(tf.getText().equals(""))
                    input.setInputVerifier(null);
                    JOptionPane.showMessageDialog(null,"Error, textfield empty");
                    input.setInputVerifier(this);
                    return false;
                  return true;
         protected class CancelListener implements ActionListener{
              public void actionPerformed(ActionEvent event) {
                   System.out.println(" cacnelListener Action");
                   dispose(); // Or System.exit(0) if you don't want to do
                   // something on close.
        public static void main(String[] args) {
            JFrame f = new VerifierTest();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setVisible(true);
    }

    thank you both. I should of use search forums with the key word. I was getting too much return with jtextfield inputverifier.
    oh well....

  • Inputverifier bug

    Hello everyone,
    I'm not sure if this is a swing bug, but the inputverifier is not called when a window hasn't focus and I click on a JTextField in that window, so that the jtextfield gets the focus at the same time as the window itself. Using this method, I can get out of an invalid JTextField to a valid one.
    Is there a workaround for this?
    Sergio S Bastos

    this code will fail and will allow focus to pass to the second jtextfield, when it should never pass. The way to make it fail it to make the window lose focus, but still make it visible. Then click on the second jtextfield. No validation will happen.
    I'm using java 1.5.0 on a windows platform...
    * NewJFrame.java
    * Created on 24 de Dezembro de 2004, 12:26
    package javaapplication1;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    * @author  Sergio Bastos
    public class NewJFrame extends javax.swing.JFrame {
        /** Creates new form NewJFrame */
        public NewJFrame() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            jPanel2 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jPanel1.setLayout(new java.awt.GridBagLayout());
            jLabel1.setText("textfield 1 ");
            jPanel1.add(jLabel1, new java.awt.GridBagConstraints());
            jTextField1.setText("jTextField1");
            jTextField1.setInputVerifier(new InputVerifier() {
                public boolean verify(JComponent input) {
                    return false;
            jPanel1.add(jTextField1, new java.awt.GridBagConstraints());
            jTextField2.setText("jTextField2");
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 1;
            jPanel1.add(jTextField2, gridBagConstraints);
            jLabel2.setText("textfield 2 ");
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            jPanel1.add(jLabel2, gridBagConstraints);
            getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
            jButton1.setText("OK");
            jPanel2.add(jButton1);
            jButton2.setText("Cancel");
            jPanel2.add(jButton2);
            getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
            pack();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        // End of variables declaration
    }

  • InputVerify ... ugly shouldYieldFocus when exit dialog or windows

    yes, maybe I should just skip InputVerify, but I figure I maybe able to learn somethere here.
    I am verifying make sure the jtextfield only has number and it's a required field, everything is okay here. but when I tried to close my dialog it pops up the InputVerify message.
    My cancel button uses
    buttonCancel.setVerifyInputWhenFocusTarget( false);  of course the dialog didn't have that method
    so I tried to search for some idea, but so far I think I had to use override shouldYeildFocus() method, but can I make the jcomponent to see it's a dialog not jtextfield??
    This is kinda close.
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=739038
    also I tried to add a method QuitListener
    protected class QuitListener implements ActionListener, WindowListener {is there a way to disable InputVerifer?
    Message was edited by:
    ekin_00
    add code around setVerifyInputWhenFocusTarget
    Message was edited by:
    ekin_00

A: InputVerify ... ugly shouldYieldFocus when exit dialog or windows

Works fine in the [url http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#inputVerification]Input Verification Demo.
I changed the code to display the panel in a dialog instead of the JFrame.
//        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        JDialog dialog = new JDialog();
        dialog.setContentPane(newContentPane);
        dialog.pack();
        dialog.setVisible(true);And if you add code to display an option pane in the verify method you need to do it like this to get around a bug:
        public boolean verify(JComponent input) {
             boolean value = checkField(input, false);
             if (value == false)
            input.setInputVerifier(null);
            JOptionPane.showMessageDialog(null, //no owner frame
                                          "something is wrong", //text to display
                                          "Invalid Value", //title
                                          JOptionPane.WARNING_MESSAGE);
            input.setInputVerifier(this);
               return value;
//            return checkField(input, false);
        }If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Works fine in the [url http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#inputVerification]Input Verification Demo.
I changed the code to display the panel in a dialog instead of the JFrame.
//        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        JDialog dialog = new JDialog();
        dialog.setContentPane(newContentPane);
        dialog.pack();
        dialog.setVisible(true);And if you add code to display an option pane in the verify method you need to do it like this to get around a bug:
        public boolean verify(JComponent input) {
             boolean value = checkField(input, false);
             if (value == false)
            input.setInputVerifier(null);
            JOptionPane.showMessageDialog(null, //no owner frame
                                          "something is wrong", //text to display
                                          "Invalid Value", //title
                                          JOptionPane.WARNING_MESSAGE);
            input.setInputVerifier(this);
               return value;
//            return checkField(input, false);
        }If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Open and cancelled Quote Report

    Hi,
    Can anyone give me the information  for getting open and cancelled Quote Report?

    I hope you are using reason for rejection for cancelling quotations. If that is the case, you can use transaction VA25 to view the list of quotations. Here you can filter on two columns status and reason for rejection to view the report as per your requirement.
    Regards,
    GSL.

  • Timeouts and "cancelled" notifications...

    Greetings,
    We are using the standard (unmodified) version of the iExpense workflows (11.5.5 on Windows, WF 2.6.1), and have a curious and annoying problem...
    1. User submits expense report
    2. "Approval Request" notification times-out (after 5 days)
    3. "No Response" e-mail notification sent back to original user.
    4. "No Response" notification times-out (after 7 days)
    5. NEW "No Response" e-mail notification generated, and sent to original user.
    6. OLD "No Response" notification cancelled automatically.
    7. "CANCELLED: No Response" e-mail notification immediately sent to original user.
    8. Same pair of notifications generated one week later (new "No Response", plus "CANCELLED: No Response" notification referring the previous week's notification), and again a week after that, and so on...
    This is maddening to our users who miss the first message, because (after that first week), they are getting PAIRS of messages every week (only seconds apart) that seem to say to them...
    Message #1: Hey, there's a problem!!
    Message #2: Oh, never mind, no problem at all.
    Has anyone else encountered this problem? How did you handle it? Any ideas?
    Thanks a bunch!! -- Tom
    [email protected]

    Hm. I've confirmed 2396373 is the patch number. Here are the steps I used to locate the patch on MetaLink:
    1) Click the Patches button on the MetaLink navigation menu.
    2) In the Patch Download page, enter 2396373 in the Patch Number field.
    3) Click Submit. This should display the platforms where the patch is available.
    Could you try one more time with these steps and see if you can access it this way?
    Regards,
    Clara
    Thanks for the feedback.
    I searched MetaLink for both the specific patch number you gave, and also the phrase (description) you gave - with no results on either search. (???) Is this patch only visible by requesting it with a TAR, or by some other means?
    Please clarify, or double-check the patch number. Thanks a bunch!! -- Tom

  • Training and Event Management - report on list of cancelled courses

    Hi All,
    Is there any standard report available to get the list of cancelled courses (be it business event grp , type or business event) Would appreciate your inputs on this.
    Kind regards
    Sathya

    S_AHR_61016216 - Cancellations per Attendee , i think there is no standard report for cencelation of business events, type and group.
    for cancellations per attendee reports is available in the system.
    good luck
    Devi

  • Depot excise invoice is open and delivery is cancelled.

    Dear Friends,
    User has created depot excise invoice (commercial invoice not created), but later he has rversed the PGI and cancelled the delivery document.  So now how to cancel the depot excise invoice.  Because system is asking for the delivery doc. number but the delivery doc. number was cancelled.
    And also please tell me how to block if excise invoice is created system should not allow the user to reverse the PGI (only when the excise invoice is cancelled then only it should allow to cancel)
    Please tell me the process how to resolve it.
    Regards,
    Sreehari
    Message was edited by:
            Sreehari Kondapalli

    Hi,
    There is no standard procedure available to cancel this as you have already cancelled the Delivery, you will have to write a ABAP code to correct this entry in RG23D table.
    Regards,
    Murali

  • Cancelled Dunning Report

    Hi Friends,
    Is there any standard tcode to display all Cancelled dunnings.
    Something like to see the list of all cancelled dunnings between 01.08.2014 till 15.08.2014 and not w.r.t to Dunning Run.
    OR
    Someone needs to write an ABAP program by hitting tables FKKMAKO, FKKMAZE and so on..
    Thanks,
    Lakshmi.

    Hi Lakhsmi
    You can see all reversed Dunning in T.code FPM3 (Dunning History). you need to select Display Reversed Dunning Not.
    Regards
    Rehan

  • I am trying to burn a CD from a playlist in iTunes. I set everything up, and then when it tries to burn, it cancels the burn right away, and gives me the error code: 4251. What am I doing wrong?

    Okay, so I wanted to burn a CD to play on players in the house. The songs on my playlist are from CDs that I own and imported into my iTunes. Here are the steps I've taken:
    1. I created a playlist
    2. Selected File > Burn Playlist to Disc...
    3. My Burn Settings are as follows: Maximum Possible Speed (I have tried all the other speeds as well with the same result), Audio CD (No gaps between songs), Use Sound Check is selected, Include CD Text is selected (I have also tried unselecting these two options).
    4. Then I clicked Burn
    5. Within a couple of seconds "Cancelling Burn" shows up in the window at the top of the screen, and a box pops up that says: The attempt to burn a disc failed. An unknown error occurred (4251).
    I have tried different CDs, I have changed all the settings in the Burn Settings box, and I get the same result over and over again. I researched the error 4251, and it refers to a problem with importing songs from a CD. This is totally irrelevant since I'm not trying to import, I'm trying to burn. This is a blank CD, and it is a CD-R. These CDs are off a tower I purchased less than a month ago, and have had absolutely no problem burning other things to these CDs. I really don't want to have to re-import these songs to Windows Media Player or another application just so I can burn what I want onto a CD, but this is almost the point I am at.
    iTunes certainly isn't helping me much at this point, and I would appreciate any feedback into what I am possibly doing wrong in trying to create a CD.

    I have Windows 7 on a Dell.  Open and play iTunes in the compatability mode and use Windows XP (service pack 2).  Disregard any messsages to disable the compability mode.  This has worked for me.  I have also reinstalled iTunes and played with burn speeds etc.  These ideas did not work.  Compatability mode works.

  • F110 Automatic payment cancel

    Hi All,
    User created vendor payments in F110, but not created the proposal and also payments went wrong and there all vendor open items cleared.
    Actually as per the monthly schedule only selected items he need to clear.
    So How to cancel the F110 payment and again how to do the same date (i.e. on 28.02.2014) payment?
    Regards,
    Raghu

    Hi Raghu,
    As Ajay mentioned, you Need to reset and reverse the Documents.
    You can use F.80 for mass reversal of documents. However, for resetting, FBRA is the only Transaction.
    BR
    Amitash

  • Report program when run in background job getting cancelled immediately

    Hi
    When i run a program in foreground i am able to see the output. But when run in background not able to run the job successfully. The job is getting cancelled immediately.
    I am using the below function module for output display. Should i need to pass any parameters in the below function module so that i can run the program in background  successfully.
      CALL METHOD DETAIL_GRID->SET_TABLE_FOR_FIRST_DISPLAY     
          EXPORTING                                            
            IS_LAYOUT         = IS_LAYOUT                    
            I_SAVE            = 'A'                        
            IS_VARIANT        = GS_VARIANT                   
          CHANGING                                           
            IT_FIELDCATALOG   = IT_FIELDCATALOG               
            IT_OUTTAB         = BLOCKED_STOCK_TAB_ALV[].     
    Please suggest.
    Thanks and regards
    Rajani Yeluri

    Hi Rajani.
      ALV require the DRYPOR(screen) for display but incase you run in back ground which have to write to spool but in spool we can only write in format of LIST REPORT not inter-active report like ALV. That why
    system cancelled your process immediately.
    Hope it helps.
    Sayan.

  • Cancelled Invoice showing as Zeros in Unaccounted Transaction Report

    The invoices were entered and the error occured because there is no currency rate conversion for entered currency , then we cancelled the invoices .It is showing as 0.00 in Unaccounted Transactions Report and need swept every month." Please suggest how to remove this from report .

    Hi,
    If it is not validated you can delete this invoice . if validated then needs to do accounting and transfer this to GL ,hopethe cancelled invoice will not have any impact on entries .
    Regards
    Muthu

  • Cancelled POs not appearing in isupplier PO Print Report

    Hi All,
    I am using oracle apps 11.5.10 version.My problem is that PO print report is not printing all the cancelled Purchase Orders.Its printing only the last Purchase Order which is cancelled.
    Steps to reproduce-
    1. create a multi line req in iproc..submit and on approval PO gets created.
    2.from isupplier run Printed PO report.You will see all the lines.
    3. Cancel 1st line in iproc-let it revision.run report from isupplier.You'll see all the lines along with one line that is cancelled.
    4.Cancel 2nd lines in iproc.let it revision.run report from isupplier.You will see all the lines and the new cancelled line as well.But the Cancelled line1 will not be seen.
    5.Again cancel 3rd line.When you print PO in isupplier.You will see all lines+3rd cancelled line.But the above two cancelled Lines 1 and 2 will b missing.
    Note- we have modifed the xslfo and po_lines_xml for some other changes.I have reverted the changes made in po_lines_xml but still facing the same issue.
    Please help.

    Hi,
    Please check in transaction  SXMB_MONI can found related information why it not transfer to SRM.
    Also check the purchasing data of the PO.
    Thanks,
    prasad.s

  • Maybe you are looking for

    • How does the Apple Headphones with Remote Replacement Program non-return fee work?

      I have a pair of Apple In-Ear Headphones with Remote and Mic that I purchased a year ago. According to the "Apple Headphones with Remote Replacement Program", http://www.apple.com/support/headphones/replacementprogram/, these headphones are also cove

    • DVDSP 4.1.2 - Not building correctly...

      I have two issues now with DVDSP (one an old issue) the other new. Both are proving to be quite irritating now. 1. This is a new issue that has cropped up. I currently have a project that, when you hit the "play" button, first plays a brief intro, ju

    • Date Format and Number Format

      Hello, Is there any possibility to change the date or number in HANA? Is it possible for a user to see amounts in the data preview as e.g. 12.000,50 vs. 12,000.50 ? What about a similar question concerning the date format? Thanks, Ingo

    • No Primary Key Column was set. (UPD_NO_PK_SET)

      I'm trying to build an update record page that gets the primary key value passed from a dynamic edit selection. dynamic list is great..opens up to the update record page great...values filled in including the primary key...i can see the primary key v

    • HBH-IS800 - Volume Too Low?

      I just got the HBH-IS800 Bluetooth earphones, which are a godsend for wireless stereo music. But, the volume on them is much lower than the stock Apple earphones. My iPhone 4 sets the volume to 100% on default, which was the first thing that made me