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 #458713] Tue, 19 July 2005 20:17
Ilya is currently offline IlyaFriend
Messages: 2
Registered: July 2009
Junior Member

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:

at java.awt.Component$NativeInLightFixer.<init>(
at java.awt.Component.addNotify(
at java.awt.Container.addNotify(
at java.awt.Window.addNotify(
at java.awt.Dialog.addNotify(
at java.awt.Window.pack(
at javax.swing.JOptionPane.createDialog(
at javax.swing.JOptionPane.showOptionDialog( 7)
at javax.swing.JOptionPane.showConfirmDialog( 68)
at javax.swing.JOptionPane.showConfirmDialog( 31)
at simple.SimpleExample$1.windowClosed(
at java.awt.Window.processWindowEvent(
at java.awt.Window.processEvent(

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.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.addWindowListener(new WindowAdapter()
* Invoked when a window has been closed.
public void windowClosed(WindowEvent e)

// Opening the shell;

// Checking to see when the display should be closed

Display display = shell.getDisplay();

while (!shell.isDisposed())
if (!display.readAndDispatch())


* This main method creates and starts an instance of the
* application.
public static void main(String[] args)
new SimpleExample().initGUI();

Frame frame;
Previous Topic:SearchDialog overrides user set layout data
Next Topic:GUIDE: how to center a JFace dialog
Goto Forum:

Current Time: Sat Oct 24 16:00:05 GMT 2020

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

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

Back to the top