Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4403182

InputVerifier failed on JTabbedPane & JMenuBar




      Name: yyT116575 Date: 01/09/2001

      C:\WINNT>java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      That's the problem :

      Case of JTabbedPane :
      I have a tabbedPane with 2 tabs where on the first tab there is a JTextField
      which the only valid text for it is : 'Sun' .I am using an InputVerifier to
      make sure the input is valid , (an error msg is popup for invalid input).

      Now , if this text field got the focus and the user enter input which is
      diffrent from 'Sun' and then press the other tab , the error msg do popup BUT
      the tab is changed WHERE i except that it won't.

      Note : all the tabs are JPanel which setVerifyInputWhenFocusTarget(true) was
             called on them as for the JTabbedPane itself.

      On JMenuBar :
      If the input is diffrent from 'Sun' and the user press the 'File' menu on the
      menubar then the same problem exsist : the error msg do popup BUT the menubar
      is opened.Worst , if the 'Exit' menu item is chosed the appliction do closed.
      Where i execpt that the InputVerifier will prevent the menu bar to open from
      the first place.

      Note : On the used JMenubar,JMenu,JMenuitem the
             setVerifyInputWhenFocusTarget(true) was called.

      Attached the code :

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class InputVerifyBugDemo
        JTextField txf1;

        public void start()
          JFrame frame = new JFrame("InputVerify Bug Demo");

        private JMenuBar createMenuBar()
          JMenuBar menubar = new JMenuBar();
          JMenu menu = new JMenu("File");
          JMenuItem item = new JMenuItem("Exit");
          item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
          //SET THE setVerifyInputWhenFocusTarget VALUE
          return menubar;

        private JTabbedPane createTabbedPane() {
        //create the tabbedPane
          JTabbedPane tabbedPane = new JTabbedPane();

          txf1 = new JTextField("only 'Sun' is valid");
          txf1.setInputVerifier(new InputVerifier() {
            public boolean shouldYieldFocus(JComponent input) {
              boolean bVerify = verify(input);
                JOptionPane.showMessageDialog(input.getParent(),"only 'Sun' is valid");
              return bVerify;
            public boolean verify(JComponent input) {

          JTextField txf2 = new JTextField("Everything valid");
          JTextField txf3 = new JTextField("Everything valid");
          tabbedPane.addTab("All others",createTab(txf3,null));
          //SET THE setVerifyInputWhenFocusTarget VALUE
          return tabbedPane;

        private JPanel createTab(JComponent cmp1,JComponent cmp2) {
          JPanel tab = new JPanel();
          cmp1.setPreferredSize(new Dimension(120,20));
          if(cmp2 != null)
            cmp2.setPreferredSize(new Dimension(120,20));
          //SET THE setVerifyInputWhenFocusTarget VALUE
          return tab;

        public static void main(String[] args) {
          (new InputVerifyBugDemo()).start();

      (Review ID: 114527)




            Unassigned Unassigned
            yyoungsunw Yung-ching Young (Inactive)
            0 Vote for this issue
            1 Start watching this issue