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"); frame.setJMenuBar(createMenuBar()); frame.getContentPane().add(createTabbedPane()); frame.show(); txf1.requestFocus(); }//method 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) { System.exit(0); } }); menu.add(item); menubar.add(menu); //SET THE setVerifyInputWhenFocusTarget VALUE menubar.setVerifyInputWhenFocusTarget(true); menu.setVerifyInputWhenFocusTarget(true); item.setVerifyInputWhenFocusTarget(true); return menubar; }//method 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); if(!bVerify) { JOptionPane.showMessageDialog(input.getParent(),"only 'Sun' is valid"); } return bVerify; } public boolean verify(JComponent input) { return((JTextField)input).getText().equals("Sun"); } }); JTextField txf2 = new JTextField("Everything valid"); JTextField txf3 = new JTextField("Everything valid"); tabbedPane.addTab("Sun",createTab(txf1,txf2)); tabbedPane.addTab("All others",createTab(txf3,null)); //SET THE setVerifyInputWhenFocusTarget VALUE tabbedPane.setVerifyInputWhenFocusTarget(true); return tabbedPane; } private JPanel createTab(JComponent cmp1,JComponent cmp2) { JPanel tab = new JPanel(); cmp1.setPreferredSize(new Dimension(120,20)); tab.add(cmp1); if(cmp2 != null) { cmp2.setPreferredSize(new Dimension(120,20)); tab.add(cmp2); } //SET THE setVerifyInputWhenFocusTarget VALUE tab.setVerifyInputWhenFocusTarget(true); return tab; }//method public static void main(String[] args) { (new InputVerifyBugDemo()).start(); }//method }//class (Review ID: 114527) ======================================================================
|