JDK-4403182 : InputVerifier failed on JTabbedPane & JMenuBar
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-01-09
  • Updated: 2017-05-23

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) 

EVALUATION Right now there is no difference between focus and selection. For example, a JList/JTable/JTabbedPane will happily changes it selection regardless of focus. The InputVerifier currently only locks focus, but it would appear it wants to lock selection as well, that is, if there is an InputVerifier and it won't give up focus, than you probably don't want to change the selection, fire listeners, or anything of that nature. We will need to address adding API to merge these two concepts into one so that InputVerifier can truly be used to lock focus and selection. scott.violet@eng 2001-07-09