Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Problem with SWT_AWT and JOptionPane
Problem with SWT_AWT and JOptionPane [message #458902] Mon, 25 July 2005 21:44 Go to next message
Ilya is currently offline IlyaFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,
I am running into a strange crash with SWT_AWT and I can't figure out how
to work around it. I am using SWT 3.1 and JDK 1.4.2.
Please help if you can.
To reproduce, run the class below and when the window shows up, close it
by pressing the X button on the top right. You get the exception:
java.lang.NullPointerException
at java.awt.Component$NativeInLightFixer.<init>(Component.java:7046)
at java.awt.Component.addNotify(Component.java:5474)
at java.awt.Container.addNotify(Container.java:2042)
at java.awt.Window.addNotify(Window.java:418)
at java.awt.Dialog.addNotify(Dialog.java:389)
at java.awt.Window.pack(Window.java:436)
at javax.swing.JOptionPane.createDialog(JOptionPane.java:917)
at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:83 7)
at javax.swing.JOptionPane.showConfirmDialog(JOptionPane.java:7 68)
at javax.swing.JOptionPane.showConfirmDialog(JOptionPane.java:7 31)
at simple.SimpleExample$1.windowClosed(SimpleExample.java:71)
at java.awt.Window.processWindowEvent(Window.java:1124)
at java.awt.Window.processEvent(Window.java:1079)
...
NOTE that I am popping up a JOptionPane dialog when the app is closing.
For instance, this could be a "Would you like to save?" dialog with Yes/No
options, so this is a pretty standard usage.
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SimpleExample
{
/**
* This method is a constructor for the application.
*/
public SimpleExample()
{
}
private void initGUI()
{
Shell shell = new Shell();
shell.setText("Test");
shell.setSize(510, 430);
// Creating a composite from the shell
Composite composite = new Composite(shell, SWT.EMBEDDED);
composite.setBounds(0, 0, 500, 400);
composite.setLayout(new RowLayout());
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
// Creating the AWT frame using the composite object
// in which the main panel will be displayed this.frame =
SWT_AWT.new_Frame(composite);
frame.add(mainPanel);
frame.addWindowListener(new WindowAdapter()
{
/**
* Invoked when a window has been closed.
*/
public void windowClosed(WindowEvent e)
{
JOptionPane.showConfirmDialog(
SimpleExample.this.frame,
"Whatever",
"Title",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
}
});
// Opening the shell
shell.open();
// Checking to see when the display should be closed
Display display = shell.getDisplay();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
/**
* This main method creates and starts an instance of the
* application.
*/
public static void main(String[] args)
{
new SimpleExample().initGUI();
}
Frame frame;
}
Re: Problem with SWT_AWT and JOptionPane [message #458927 is a reply to message #458902] Tue, 26 July 2005 17:47 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Ilya, please enter a bug report with the code and someone will look at it.
Thanks.

"Ilya Frank" <ifrank@tomsawyer.com> wrote in message
news:231207a576bd1093b63b9f6c7519a550$1@www.eclipse.org...
> Hi,
> I am running into a strange crash with SWT_AWT and I can't figure out how
> to work around it. I am using SWT 3.1 and JDK 1.4.2.
> Please help if you can.
> To reproduce, run the class below and when the window shows up, close it
> by pressing the X button on the top right. You get the exception:
> java.lang.NullPointerException
> at java.awt.Component$NativeInLightFixer.<init>(Component.java:7046)
> at java.awt.Component.addNotify(Component.java:5474)
> at java.awt.Container.addNotify(Container.java:2042)
> at java.awt.Window.addNotify(Window.java:418)
> at java.awt.Dialog.addNotify(Dialog.java:389)
> at java.awt.Window.pack(Window.java:436)
> at javax.swing.JOptionPane.createDialog(JOptionPane.java:917)
> at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:83 7)
> at javax.swing.JOptionPane.showConfirmDialog(JOptionPane.java:7 68)
> at javax.swing.JOptionPane.showConfirmDialog(JOptionPane.java:7 31)
> at simple.SimpleExample$1.windowClosed(SimpleExample.java:71)
> at java.awt.Window.processWindowEvent(Window.java:1124)
> at java.awt.Window.processEvent(Window.java:1079)
> ..
> NOTE that I am popping up a JOptionPane dialog when the app is closing.
> For instance, this could be a "Would you like to save?" dialog with Yes/No
> options, so this is a pretty standard usage.
> import java.awt.*;
> import java.awt.event.WindowAdapter;
> import java.awt.event.WindowEvent;
> import javax.swing.*;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.awt.SWT_AWT;
> import org.eclipse.swt.layout.RowLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> public class SimpleExample
> {
> /**
> * This method is a constructor for the application.
> */
> public SimpleExample()
> {
> }
> private void initGUI()
> {
> Shell shell = new Shell();
> shell.setText("Test");
> shell.setSize(510, 430);
> // Creating a composite from the shell
> Composite composite = new Composite(shell, SWT.EMBEDDED);
> composite.setBounds(0, 0, 500, 400);
> composite.setLayout(new RowLayout());
> JPanel mainPanel = new JPanel();
> mainPanel.setLayout(new BorderLayout());
> // Creating the AWT frame using the composite object
> // in which the main panel will be displayed this.frame =
> SWT_AWT.new_Frame(composite);
> frame.add(mainPanel);
> frame.addWindowListener(new WindowAdapter()
> {
> /**
> * Invoked when a window has been closed.
> */
> public void windowClosed(WindowEvent e)
> {
> JOptionPane.showConfirmDialog(
> SimpleExample.this.frame,
> "Whatever",
> "Title",
> JOptionPane.YES_NO_CANCEL_OPTION,
> JOptionPane.WARNING_MESSAGE);
> }
> });
> // Opening the shell
> shell.open();
> // Checking to see when the display should be closed
> Display display = shell.getDisplay();
> while (!shell.isDisposed())
> {
> if (!display.readAndDispatch())
> {
> display.sleep();
> }
> }
> display.dispose();
> }
> /**
> * This main method creates and starts an instance of the
> * application.
> */
> public static void main(String[] args)
> {
> new SimpleExample().initGUI();
> }
> Frame frame;
> }
>
>
Previous Topic:Catching key pressing
Next Topic:text under image on a label
Goto Forum:
  


Current Time: Fri Apr 26 03:30:19 GMT 2024

Powered by FUDForum. Page generated in 0.03053 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top