JDK-4988884 : Can't open functional modeless dialogs when a modal dialpg is displayed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-02-04
  • Updated: 2005-08-11
  • Resolved: 2005-08-11
Related Reports
Duplicate :  
Description
Name: rl43681			Date: 02/04/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b31)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b31, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
I have an option pane in my application that has a sort of help button that is to bring up a modeless window with some reference information while working in the modal option dialog.   It seems this does not work.
The parent/owner of the modeless dialog is null.  If I try a JFrame instead of a modeless JDialog the frame can't even be dragged.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test case below and observe how the  scroll bar is not funcitonal in the final dialog after pressing the buttons to open the modal dialog. (JOptionPane)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should eb possible to create functional modeless dialogs when an application has a modal dialog displayed.
ACTUAL -
The modeless dialogs or other frames are non-functional until the modal dialog is closed.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// JDialog JScrollPane problem

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class DialogSP
{
	public static void main(String [] args)
	{
		final JFrame f = new JFrame("DialogSP");
		JButton button = new JButton("Press Me...");
		f.getContentPane().add(button,BorderLayout.CENTER);
		f.pack();
		
		button.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{
				JOptionPane.showConfirmDialog(
				f,
				new OptionMessage(),
				"Blah",
				JOptionPane.OK_CANCEL_OPTION,
				JOptionPane.PLAIN_MESSAGE );
			}
		});
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
	}
	public static final String msg = "Note this is not the same as  Bug Id   	  4501654\n"
		+"The modeless windows do not have the same parent as the modal dialog\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"sdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\nsdfg\n"
		+"Note this is not the same as  Bug Id   	  4501654\n"
		+"The modeless windows do not have the same parent as the modal dialog\n";
}

class OptionMessage extends JPanel
{
	OptionMessage()
	{
		JButton button = new JButton("Open JDialog then try to scroll...");
		button.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{
				createModelessInfoDialog();
			}
		});
		add(button);
		JButton button2 = new JButton("Open JFramer then try to scroll or move the frame...");
		button2.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{
				createInfoFrame();
			}
		});
		add(button2);
	}
	public void createModelessInfoDialog()
	{
		JDialog info = new ViewerDialog(
					null,
					"Modeless JDialog with null parent" );
		info.pack();
		info.setSize(640,480);
		info.setModal( false );
		info.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
		info.setVisible( true );
	}
	public void createInfoFrame()
	{
		JFrame info = new ViewerFrame("JFrame" );
		info.pack();
		info.setSize(640,480);
		info.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
		info.setVisible( true );
	}
}


class ViewerDialog extends JDialog
{
	public ViewerDialog( Frame owner, String title )
	{
		super( owner, title );
		JEditorPane dispArea;
		dispArea = new JEditorPane("text/plain",DialogSP.msg);
		dispArea.setEditable(false);
		getContentPane().add(new JScrollPane(dispArea), BorderLayout.CENTER);
	}
}
class ViewerFrame extends JFrame
{
	public ViewerFrame( String title )
	{
		super( title );
		JEditorPane dispArea;
		dispArea = new JEditorPane("text/plain",DialogSP.msg);
		dispArea.setEditable(false);
		getContentPane().add(new JScrollPane(dispArea), BorderLayout.CENTER);
	}
}
---------- END SOURCE ----------
(Incident Review ID: 235339) 
======================================================================

Comments
EVALUATION Name: ibR10256 Date: 03/05/2004 See the javadoc for java.awt.Dialog: "A modal dialog is one which blocks input to all other toplevel windows in the application, except for any windows created with the dialog as their owner." The modeless dialog which is created in the submitted code has null parent, and so is legally non-functional. Frames cannot get into the modal dialogs children hierarchy (they are not allowed to have owners) so they will be always blocked when there is an opened modal dialog. So I think this is not a bug. To avoid the problem with the modeless dialog the submitter should replace this code: JOptionPane.showConfirmDialog(f, new OptionMessage(), "Blah", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); with something like: JOptionPane jop = new JOptionPane(new OptionMessage(), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); jopDialog = jop.createDialog(f, "Blah"); jopDialog.setVisible(true); assuming this declaration: JDialog jopDialog; And then make jopDialog the owner of ViewerDialog. ###@###.### 2004-03-05 ====================================================================== Name: ibR10256 Date: 03/05/2004 In addition to my previous evaluation: The fact that the modeless JDialog that is created from the JOptionPane and has null parent can be dragged and resized is most probably a bug. See 4256692 and 4793073. ###@###.### 2004-03-05 ======================================================================
05-03-2004