JDK-4089768 : Dialog Z-order behavior should be precisely specified
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.4,1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1997-10-30
  • Updated: 2001-06-11
  • Resolved: 2001-06-11
Related Reports
Duplicate :  
Description

Name: joT67522			Date: 10/30/97


I did the following under 1.1.3:

1) I ran a modal dialog from a frame. 
2) I created a modeless dialog which appeared on top of the modal dialog.  
3) I called request focus for a component on the modal dialog.  This made the 
modal dialog active, but the modeless dialog was still on top of it.  
4) This is the result that I want. 

Under 1.1.4, when I do the requestFocus, the modeless dialog gets covered up.  
I can't find any way around this.  I need the modeless dialog to stay on top, 
but the modal dialog needs to have the focus.


import java.awt.*; 
import java.awt.event.*; 

public class TestFocus extends Frame
{
	public static void main(String[] args)
	{
		TestFocus frame = new TestFocus("TestFocus"); 
		frame.setSize(300,300);
		frame.setVisible(true); 
		frame.test(); 
	}

	public TestFocus(String title)
	{
		super(title); 
	}

	public void test()
	{
		TestFocusDialog dlg = new TestFocusDialog(this, "Modal", true); 
		dlg.setSize(200,200);
		dlg.addWindowListener(new ModalAdapter(this)); 
		dlg.setVisible(true); 
	}
}

class TestFocusDialog extends Dialog
{
	public TestFocusDialog(Frame frame, String title, boolean modal)
	{
		super(frame, title, modal); 
	}
}

class ModalAdapter extends WindowAdapter
{
	private Frame frame = null; 
	private Dialog dialog = null; 

	public ModalAdapter(Frame frame)
	{
		this.frame = frame; 
	}

	public void windowOpened(WindowEvent e)
	{ 
		// Create a modeless dialog over this modal dialog. 

		TestFocusDialog dlg = new TestFocusDialog(frame, "Modeless", false); 
		dialog = dlg; 

		dlg.setSize(150,150);
		dlg.move(75,75); 
		dlg.addWindowListener(new ModelessAdapter((Dialog)e.getSource())); 
		dlg.setVisible(true); 
	}

	public void windowActivated(WindowEvent e)
	{
		// Whenever this window is activated, bring the modeless 
		// dialog to the front. Using setVisible is the only way 
		// I've found to put a dialog on top. Unfortunately this 
		// also activates the window.  

		if(dialog != null)
			dialog.setVisible(true); 
	}
}

class ModelessAdapter extends WindowAdapter
{
	private Dialog dialog = null; 

	public ModelessAdapter(Dialog dialog)
	{
		this.dialog = dialog; 
	}

	public void windowActivated(WindowEvent e)
	{ 
		// When this dialog was activated, it took the focus from the modal 
		// dialog. Put the focus back on the modal dialog. 

		dialog.requestFocus(); 
	}
}

(Review ID: 19105)
======================================================================

Name: krC82822			Date: 02/05/2001


Windows:
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)

Solaris:
java version "1.3.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)


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


public class FrameTest extends JFrame {

  public FrameTest() {
  }
  public static void main(String[] args) {
    FrameTest frameTest = new FrameTest();
    frameTest.setSize(300,300);
    JDialog dlg = new JDialog(frameTest);
    frameTest.setVisible(true);
    dlg.setSize(100,100);
    dlg.show();
  }
}


the code above will display the Dialog always on top of the frame when runs on win32. On Solaris, on the other hand, the dialog can be hidden behind the frame.
(Review ID: 116363)
======================================================================

Comments
WORK AROUND Name: joT67522 Date: 10/30/97 I can't find a workaround in 1.1.4. That's the problem. ======================================================================
11-06-2004

EVALUATION We need to spec the behavior of this situation. We have to state that whether a Dialog is always on top of its owner is platform-dependent. This appears to be the case on Windows, but is not always true on Solaris (varies by window manager). It may also not be desirable behavior on the Mac. We intend to resolve this as part of the Z-order project for tiger. david.mendenhall@eng 1999-12-14
14-12-1999