JDK-4707289 : 1.4 REGRESSION: JApplet should have a focus traversal policy.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0,1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt,windows_2000
  • CPU: x86
  • Submitted: 2002-06-24
  • Updated: 2003-04-12
  • Resolved: 2002-08-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
1.4.0_04 04Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
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
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

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

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

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