United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4707289 : 1.4 REGRESSION: JApplet should have a focus traversal policy.

Details
Type:
Bug
Submit Date:
2002-06-24
Status:
Resolved
Updated Date:
2003-04-12
Project Name:
JDK
Resolved Date:
2002-08-12
Component:
client-libs
OS:
windows_nt,windows_2000
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0,1.4.1
Fixed Versions:
1.4.0_04 (04)

Related Reports
Backport:
Backport:
Duplicate:
Duplicate:
Relates:

Sub Tasks

Description
JApplet is a container and should have a new focus traversal policy and should be a focus cycle root. Without a focus policy, Tab and Shift-Tab will not move to other components when using components added to the content pane of an applet.

The requestFocus() call seems to work on components since the mnemonic and setLabelFor bindings are still valid.

This regression was introduced in 1.4 as a result of the new focus manager enhancements. This last worked in 1.3.1.

Test case:


>>>>>>>>>>>>>>>>>>>>>>>>>> JAppletTest.java 
import javax.swing.*;
import java.awt.event.KeyEvent;

/**
 * Test case for FocusManager regression. JApplet non-focus traversal policy. 
 * To reproduce: Use the appletviewer to start the applet. TAB and SHIFT-TAB 
 * have no effect on focus traversal.
 * 
 * Note: the mnemonic key bindings still work. 
 */
public class JAppletTest extends JApplet {

    // Running the panel in a JApplet doens't allow focus traversal.
    public void init() {
	setContentPane(createPanel());
    }

    private static JPanel createPanel() {
	JTextField tf = new JTextField("text in Text field");
	JLabel label = new JLabel("Label for Text Field");
	label.setDisplayedMnemonic(KeyEvent.VK_L);
	label.setLabelFor(tf);

	JButton button = new JButton("Button");

	// XXX - Hmmmm.... shouldn't there be a setDisplayedMnemonic in JButton?
	// Perhaps there should be a setMnemoic in JLabel?
	button.setMnemonic(KeyEvent.VK_B);

	JPanel panel = new JPanel();
	panel.add(button);
	panel.add(label);
	panel.add(tf);
	
	return panel;
    }

    // Running the panel in a JFrame allows focus traversal.
    public static void main(String[] args) {
	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setContentPane(createPanel());
	frame.pack();
	frame.setVisible(true);
    }
}

<<<<<<<<<<<<<<<<<<< JAppletTest.java

>>>>>>>>>>>>>>>>>>> JAppletTest.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title></title>
  </head>

  <body>
    <h1></h1>
    <applet code="JAppletTest.class" width="400" height="200"></applet>

    <hr>
<!-- Created: Mon Jun 24 15:37:58 Pacific Daylight Time 2002 -->
<!-- hhmts start -->
Last modified: Mon Jun 24 15:38:27 Pacific Daylight Time 2002
<!-- hhmts end -->
  </body>
</html>



                                    

Comments
SUGGESTED FIX



Name: apR10133			Date: 07/25/2002



------- JApplet.java -------
*** /tmp/sccs.8UaGhS	Wed Jul 24 20:33:19 2002
--- JApplet.java	Wed Jul 24 20:33:01 2002
***************
*** 117,123 ****
          setLayout(new BorderLayout());
          setRootPane(createRootPane());
          setRootPaneCheckingEnabled(true);
! 
          enableEvents(AWTEvent.KEY_EVENT_MASK);
      }
  
--- 117,131 ----
          setLayout(new BorderLayout());
          setRootPane(createRootPane());
          setRootPaneCheckingEnabled(true);
! 	
! 	// This code should be changed after the RFE 4719336 is resolved
! 	// to not make the applet a FocusCycleRoot, but set it's
! 	// FocusTraversalPolicy only.
! 	setFocusCycleRoot(true);
! 	setFocusTraversalPolicy(KeyboardFocusManager.
! 				getCurrentKeyboardFocusManager().
! 				getDefaultFocusTraversalPolicy());
! 	
          enableEvents(AWTEvent.KEY_EVENT_MASK);
      }
  

###@###.###

======================================================================
                                     
2004-08-24
WORK AROUND

Use JFrame, JWindows or JDialog as the top level container.
                                     
2004-08-24
EVALUATION



Name: apR10133			Date: 07/25/2002


    JApplet should have a FocusTraverlasPolicy. But it shouldn't be
a focus cycle root (otherwise in AppletViewer and Plugin containers
applet doesn't receive focus by default but focus can be transfered
to first component by the TAB). We can set the FTP for focus cycle
root only. So, we will make the JApplet a focus cycle root until the
RFE 4719336 is done.

###@###.###

======================================================================
                                     
2004-08-24
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.0_04
1.4.1_02
mantis
mantis-b02

FIXED IN:
1.4.0_04
1.4.1_02
mantis
mantis-b02

INTEGRATED IN:
1.4.0_04
1.4.1_02
mantis
mantis-b02


                                     
2004-08-24



Hardware and Software, Engineered to Work Together