-
Bug
-
Resolution: Fixed
-
P2
-
1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2.0
-
1.2beta2
-
generic, x86, sparc
-
solaris_2.5, solaris_2.5.1, solaris_2.6, windows_nt
-
Verified
With swing-0.5.1 and JDK1.2P2, in the SwingSet example, on Windows 95, if you bring up a dialog and then dismiss you get the following exceptions:
Exception occurred during event dispatching:
java.lang.NullPointerException:
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1546)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1450)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1382)
at java.awt.Container.dispatchEventImpl(Container.java:921)
at java.awt.Window.dispatchEventImpl(Window.java:462)
at java.awt.Component.dispatchEvent(Component.java:1823)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:45)
Steps to Reproduce
0) Set all corrects paths and system variables.
1) Recompile the SwingSet demo (the win32.mak file did not work for me even with adjustments. I just typed "javac *.java" and that worked.
2) Run using the runnit file.
3) Select any one of the dialogs from the Dialogs menu.
4) Dismiss the dialog by either double clicking on the top left corner, or using the close box for the dialog.
RESULT: The exceptions listed above.
nancy.schorr@eng 1997-11-10:
This bug appears to be fixed in the JDK1.2T build with Swing-0.6 built into the classes.zip file.
=============================================================
// File: ToolBug.java
// November 21, 1997
//
// This class creates a Swing-based application that does not do anything
// other than demonstrate an exception thrown by closing a modal dialog or
// JOptionPane that was displayed in response to an ActionEvent fired by
// a Swing ToolBar button.
//
// Note: Displaying the dialog from an AWT MenuItem does not generate the
// exception, and can also be demonstrated with this example.
//
// Compiling will generate a deprecation warning, because Dialog.show() is
// overridden in the NativeDialog class, even though Dialog.show() is not
// documented as deprecated. The compiler sees this as overriding
// Component.show(), which is deprecated per AWT documentation.
//
// Build with JDK 1.1.4
// Behavior observed in Win95 and SPARC/Solaris 2.5.1
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.border.*;
import com.sun.java.swing.basic.*;
import com.sun.java.swing.plaf.*;
/**
* This class creates a "do-nothing" modal dialog with a message
* and an OK button.
*/
class NativeDialog extends Dialog
implements ActionListener
{
Button okbutton;
public NativeDialog(Frame frame, String title, String message)
{
super(frame, title, true);
setBackground(Color.lightGray);
setLayout(new BorderLayout());
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
};
addWindowListener(l);
Label lbl = new Label(message);
okbutton = new Button("OK");
okbutton.addActionListener(this);
add("Center",lbl);
add("South", okbutton);
setSize(200,100);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(okbutton)){
setVisible(false);
}
}
///////////////////////////////////////////////////////////////
//Note: Overriding Dialog.show() causes a deprecation warning
//even though Dialog.show() is not documented as deprecated.
//The compiler sees this as overriding Component.show(), which
//is deprecated. Which is correct?
///////////////////////////////////////////////////////////////
public void show()
{
Dimension screenSize = getToolkit().getScreenSize();
setLocation((screenSize.width - getSize().width)/2,
(screenSize.height - getSize().height)/2);
super.show();
}
}
/**
* This class creates a Swing-based application that does not do anything
* other than demonstrate an exception thrown by closing a modal dialog or
* JOptionPane that was displayed in response to an ActionEvent fired by
* a Swing ToolBar button.
*/
public class ToolBug extends JPanel
implements ActionListener
{
static JFrame frame;
JPanel toolBar;
JButton jbModal,
jbOptionPane;
MenuItem miModal,
miOptionPane,
miQuit;
public ToolBug()
{
super(true);
setLayout(new BorderLayout());
toolBar = getToolBar();
MenuBar menubar = getMenu();
add("North",toolBar);
JPanel spanel = new JPanel(new BorderLayout());
spanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
JLabel lbl = new JLabel("This app doesn't do anything. Just try the toolbar buttons.",
SwingConstants.CENTER);
lbl.setFont(new Font("serif",Font.BOLD,18));
spanel.add("Center",lbl);
add("Center", spanel);
frame.setMenuBar(menubar);
}
public MenuBar getMenu()
{
MenuBar menubar = new MenuBar();
Menu files = new Menu("Files");
miModal = files.add(new MenuItem("Native Modal Dialog..."));
miModal.addActionListener(this);
miOptionPane = files.add(new MenuItem("JOptionPane..."));
miOptionPane.addActionListener(this);
files.add(new MenuItem("-"));
miQuit = files.add(new MenuItem("Quit"));
miQuit.setShortcut(new MenuShortcut(KeyEvent.VK_Q));
miQuit.addActionListener(this);
menubar.add(files);
return menubar;
}
public JPanel getToolBar()
{
JToolBar toolBar = new JToolBar();
ToolBarUI tui = toolBar.getUI();
((BasicToolBarUI)tui).setFloatable(false);
jbModal = addTool(toolBar, "Native", "Native Modal Dialog", true);
toolBar.addSeparator();
jbOptionPane = addTool(toolBar, "Swing", "JOptionPane Dialog", true);
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add("South",toolBar);
return p1;
}
public JButton addTool(JToolBar toolBar, String name, String tip, boolean state)
{
JButton b =
(JButton) toolBar.add(
new JButton(name));
b.setToolTipText(tip);
b.setEnabled(state);
b.setMargin(new Insets(0,2,0,2));
b.addActionListener(this);
return b;
}
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
if(src.equals(jbModal) || src.equals(miModal)){
NativeDialog dlg = new NativeDialog(frame,"Native Dialog", "Native Dialog Test");
dlg.show();
dlg.dispose();
}
else if(src.equals(jbOptionPane) || src.equals(miOptionPane)){
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue =
JOptionPane.showInputDialog(
null,
"Choose one",
"Input",
JOptionPane.INFORMATION_MESSAGE,
null,
possibleValues,
possibleValues[0]);
}
else if(src.equals(miQuit)){
System.exit(0);
}
}
public static void main(String s[])
{
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
frame = new JFrame("ToolBar Bug Example");
frame.setBackground(Color.lightGray);
frame.addWindowListener(l);
frame.getContentPane().add(new ToolBug());
frame.setSize(550,225);
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - frame.getSize().width)/2,
(screenSize.height - frame.getSize().height)/2);
frame.setVisible(true);
}
}
========================================================
Exception occurred during event dispatching:
java.lang.NullPointerException:
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1546)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1450)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1382)
at java.awt.Container.dispatchEventImpl(Container.java:921)
at java.awt.Window.dispatchEventImpl(Window.java:462)
at java.awt.Component.dispatchEvent(Component.java:1823)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:45)
Steps to Reproduce
0) Set all corrects paths and system variables.
1) Recompile the SwingSet demo (the win32.mak file did not work for me even with adjustments. I just typed "javac *.java" and that worked.
2) Run using the runnit file.
3) Select any one of the dialogs from the Dialogs menu.
4) Dismiss the dialog by either double clicking on the top left corner, or using the close box for the dialog.
RESULT: The exceptions listed above.
nancy.schorr@eng 1997-11-10:
This bug appears to be fixed in the JDK1.2T build with Swing-0.6 built into the classes.zip file.
=============================================================
// File: ToolBug.java
// November 21, 1997
//
// This class creates a Swing-based application that does not do anything
// other than demonstrate an exception thrown by closing a modal dialog or
// JOptionPane that was displayed in response to an ActionEvent fired by
// a Swing ToolBar button.
//
// Note: Displaying the dialog from an AWT MenuItem does not generate the
// exception, and can also be demonstrated with this example.
//
// Compiling will generate a deprecation warning, because Dialog.show() is
// overridden in the NativeDialog class, even though Dialog.show() is not
// documented as deprecated. The compiler sees this as overriding
// Component.show(), which is deprecated per AWT documentation.
//
// Build with JDK 1.1.4
// Behavior observed in Win95 and SPARC/Solaris 2.5.1
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.border.*;
import com.sun.java.swing.basic.*;
import com.sun.java.swing.plaf.*;
/**
* This class creates a "do-nothing" modal dialog with a message
* and an OK button.
*/
class NativeDialog extends Dialog
implements ActionListener
{
Button okbutton;
public NativeDialog(Frame frame, String title, String message)
{
super(frame, title, true);
setBackground(Color.lightGray);
setLayout(new BorderLayout());
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
};
addWindowListener(l);
Label lbl = new Label(message);
okbutton = new Button("OK");
okbutton.addActionListener(this);
add("Center",lbl);
add("South", okbutton);
setSize(200,100);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(okbutton)){
setVisible(false);
}
}
///////////////////////////////////////////////////////////////
//Note: Overriding Dialog.show() causes a deprecation warning
//even though Dialog.show() is not documented as deprecated.
//The compiler sees this as overriding Component.show(), which
//is deprecated. Which is correct?
///////////////////////////////////////////////////////////////
public void show()
{
Dimension screenSize = getToolkit().getScreenSize();
setLocation((screenSize.width - getSize().width)/2,
(screenSize.height - getSize().height)/2);
super.show();
}
}
/**
* This class creates a Swing-based application that does not do anything
* other than demonstrate an exception thrown by closing a modal dialog or
* JOptionPane that was displayed in response to an ActionEvent fired by
* a Swing ToolBar button.
*/
public class ToolBug extends JPanel
implements ActionListener
{
static JFrame frame;
JPanel toolBar;
JButton jbModal,
jbOptionPane;
MenuItem miModal,
miOptionPane,
miQuit;
public ToolBug()
{
super(true);
setLayout(new BorderLayout());
toolBar = getToolBar();
MenuBar menubar = getMenu();
add("North",toolBar);
JPanel spanel = new JPanel(new BorderLayout());
spanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
JLabel lbl = new JLabel("This app doesn't do anything. Just try the toolbar buttons.",
SwingConstants.CENTER);
lbl.setFont(new Font("serif",Font.BOLD,18));
spanel.add("Center",lbl);
add("Center", spanel);
frame.setMenuBar(menubar);
}
public MenuBar getMenu()
{
MenuBar menubar = new MenuBar();
Menu files = new Menu("Files");
miModal = files.add(new MenuItem("Native Modal Dialog..."));
miModal.addActionListener(this);
miOptionPane = files.add(new MenuItem("JOptionPane..."));
miOptionPane.addActionListener(this);
files.add(new MenuItem("-"));
miQuit = files.add(new MenuItem("Quit"));
miQuit.setShortcut(new MenuShortcut(KeyEvent.VK_Q));
miQuit.addActionListener(this);
menubar.add(files);
return menubar;
}
public JPanel getToolBar()
{
JToolBar toolBar = new JToolBar();
ToolBarUI tui = toolBar.getUI();
((BasicToolBarUI)tui).setFloatable(false);
jbModal = addTool(toolBar, "Native", "Native Modal Dialog", true);
toolBar.addSeparator();
jbOptionPane = addTool(toolBar, "Swing", "JOptionPane Dialog", true);
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add("South",toolBar);
return p1;
}
public JButton addTool(JToolBar toolBar, String name, String tip, boolean state)
{
JButton b =
(JButton) toolBar.add(
new JButton(name));
b.setToolTipText(tip);
b.setEnabled(state);
b.setMargin(new Insets(0,2,0,2));
b.addActionListener(this);
return b;
}
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
if(src.equals(jbModal) || src.equals(miModal)){
NativeDialog dlg = new NativeDialog(frame,"Native Dialog", "Native Dialog Test");
dlg.show();
dlg.dispose();
}
else if(src.equals(jbOptionPane) || src.equals(miOptionPane)){
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue =
JOptionPane.showInputDialog(
null,
"Choose one",
"Input",
JOptionPane.INFORMATION_MESSAGE,
null,
possibleValues,
possibleValues[0]);
}
else if(src.equals(miQuit)){
System.exit(0);
}
}
public static void main(String s[])
{
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
frame = new JFrame("ToolBar Bug Example");
frame.setBackground(Color.lightGray);
frame.addWindowListener(l);
frame.getContentPane().add(new ToolBug());
frame.setSize(550,225);
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - frame.getSize().width)/2,
(screenSize.height - frame.getSize().height)/2);
frame.setVisible(true);
}
}
========================================================
- duplicates
-
JDK-4058359 LightweightDispatcher has race problem with Modal dialogs.
-
- Closed
-
-
JDK-4061337 Modal dialogs which were launched by JButton cause NULLPointerException.
-
- Closed
-
-
JDK-4078091 AWT throws exception in lightweight event handling
-
- Closed
-