JDK-4302764 : focus is not set in JInternalFrame
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0,1.4.0,1.4.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_98,windows_nt
  • CPU: generic,x86
  • Submitted: 2000-01-05
  • Updated: 2005-04-27
  • Resolved: 2005-04-27
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 Availability Release.

To download the current JDK release, click here.
JDK 6
6 b34Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description

Name: skT88420			Date: 01/05/2000


java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)

I have a JDesktopPane and many internal frame
when the focus is in one of them, if I select another component outside of the
JDesktopPane and then I select the foreground Internal Frame with the border,
the focus is not set to the content of the frame.

example :

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

public class FrameBug extends JInternalFrame
{
	static void main(String[] args)
	{
		JDialog dialog = new JDialog((Frame) null, true);

		dialog.setSize(new Dimension(1000,600));
		BorderLayout borderLayout_ = new BorderLayout();
		dialog.getContentPane().setLayout( borderLayout_ );

		final JDesktopPane desktopPane = new JDesktopPane();

		dialog.getContentPane().add(desktopPane,BorderLayout.CENTER);
		dialog.getContentPane().add(new
JTextField(),BorderLayout.SOUTH);
			
		for (int i = 0 ; i < 2 ; i++)
		{
			JInternalFrame frame  = new
JInternalFrame("test",true,true,true,true);

			frame.getContentPane().add(new JTextArea("test " + i));
			frame.pack();
			frame.setBounds(new Rectangle(i*30,i*30,400, 400));

			frame.setVisible(true);
			
			desktopPane.add(frame);
		}

		dialog.setVisible(true);

		System.exit(0);
	}
}

with this example, anytime you select a frame with the border the focus is set
on the content of it (the text area). But if you select the TextField on the
south and then the foreground frame with the border the textarea don't have
focus.
(Review ID: 99617) 
======================================================================

Comments
EVALUATION This is indeed broken, but it's a somewhat esoteric case and one that's easy to recover from, so it doesn't seem like an S1 bug to me. This will be fixed with the focus re-write for merlin. hania.gajewska@Eng 2000-01-13 Name: dkR10074 Date: 11/01/2000 ###@###.### 2000-11-01 I can't reproduce the bug as described in the bug report. But there is another way to reproduce the bug. SunOS_sparc promoted b34 - FAILED It's enough to select one internal frame and then another by clicking on the title bar. The text area doesn't gain the focus in both frames. promoted b35 - FAILED The behavior is the same as b34, but there are differences. The text area doesn't gain the focus only in the second frame. After selecting the text field, each selection of the first frame moves the focus to the text field. promoted b36 - FAILED The behavior is the same as b35. Windows_NT_x86 promoted b34 - FAILED The behavior is the same as b34 in the SunOS_sparc section. promoted b35 - FAILED The behavior is the same as b35 in the SunOS_sparc section. promoted b36 - FAILED The behavior is the same as b36 in the SunOS_sparc section. ====================================================================== Name: keR10081 Date: 11/08/2000 The reason for this bug follows: If we switch between internal frames, then in process of dispatching FOCUS_LOST event DefaultKeyboardFocusManager calls setGlobalPermanentFocusOwner(null), which in turn calls setMostRecentFocusOwner(null). When we switch back to that internal frame, the component of internal frame, which should be focused on internal frame's FOCUS_GAINED is most recent focus owner, which has been set to null. That's why text area doesn't get focus. ====================================================================== Talked to hania.gajewska@eng. She thinks this will not be a showstopper for Merlin, although we should fix it if we have time and resources. Decommitting. eric.hawkes@eng 2001-03-21 Name: osR10079 Date: 12/18/2001 The problem is as follows: if we click on the border of internal frame mousePressed() method of javax.swing.plaf.basic.BasicInternalFrameUI.BorderListener is called. And this method makes internal frame selected by setSelected(true) call if internal frame is not already selected. JInternalFrame.setSelected(), in turn, should set focus on correct component inside the internal frame. In our case, the following scenario happens: 1. We click on JInternalFrame. It becomes selected. 2. We click on JTextField, which is not in any of internal frames, but in the same toplevel container (JFrame). As a result, the focus moves to JTextField, but the internal frame remains selected. 3. After that, we click on the border of the internal frame. However, it is already selected. So the sequence of calls described above which should lead to correct focus placement, does not happen. Thus, it looks like a Swing problem. Reassigning to Swing for further investigation. ###@###.### 18 Dec 2001 ====================================================================== This bug is not fixed by the focus re-write. The implementation has a number of problems and makes assumptions about selection. Decommitting from 1.4.1. If this does not require API changes I will try to make it into the next dot release. ###@###.### 2002-04-17 First part of the problem is once an internal frame is selected the action it will not be reselected if clicked on. The problem with this is the restore focus code is in the selection method. The second problem is with getMostRecentFocusOwner which could return null prematurely. And finally, restoreSubcomponentFocus overwrote the lastFocusOwner even if it wasn't null. There are still a few problems with tracking the last focus owner, but at least this is a start. ###@###.### 2003-10-29 src/share/classes/javax/swing/JInternalFrame.java In setSelected, call restoreSubcomponentFocus if already selected. Keep lastFocusOwner state. Do not set to null at end of setSelected. Update the lastFocusOwner from a FocusPropertyChangeListener. src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java Always call frame.setSelected(true) when mousePressed. ###@###.### 2005-03-26 00:20:14 GMT ###@###.### 2005-04-12 23:33:05 GMT
26-03-2005