Non modal optionpane

hello,
i wanted to use an option pane with a string array to display a list
i thought using the api would be easier because all of the formating and things is allready done but i want it to be non modal,
i found this thread [http://forum.java.sun.com/thread.jspa?threadID=744269&messageID=4262681] but i dont really understand whats goin on, i dont need to know anything about the users interaction with this dialog box
thanks in advance
alex

The api gives an example. something like this has worked for me:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
public class NonModalJOptionPane extends JFrame
    public NonModalJOptionPane()
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton button = new JButton("Press me");
        button.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent arg0)
                JOptionPane myOptionPane = new JOptionPane("Hey, hey, my, my",
                    JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION);
                JDialog dialog = myOptionPane.createDialog(
                    NonModalJOptionPane.this, "Rock and Roll Will Never Die");
                dialog.setModal(false);
                dialog.setVisible(true);
        add(button);
        pack();
        setLocationRelativeTo(null);
    public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable()
            public void run()
                new NonModalJOptionPane().setVisible(true);
}

Similar Messages

  • JDialog Non Modal....Default button remains

    I've created a non modal JDialog
    By doing the following
    1. Creating an object of JOptionPane(message, JOptionPane.ERROR_MESSAGE)
    2. Adding the JOptionPane object to the ContentPane
    3. Creating a button
    4. Adding button("End Application") to ContentPane
    5. Adding listeners to window and button
    The result is a dialog
    Message
    ICON "OK" Button...............................NOT REQUIRED
    "End Application" Button
    I don't require the "OK" Button. Is there a way of removing this button. I need the dialog box to be modal so can't use showMessageDialog, rename "Ok" button to "End Application" etc.
    Should I be taking a different approach ie Not adding JOptionPane to JDialog??
    If the above isn't possible. Do you know where I can find the default error gif on error dialog boxes?
    Kind regards,
    Jean

    Get the error icon with UIMananger.getIcon("OptionPane.errorIcon"). It might throw exceptions while painting because it's expecting to be painting in a JOptionPane. Just catch and ignore the exceptions and it will paint alright.

  • Feature request: make the "transform" dialogs non-modal

    Currently, the transformation dialogs accessible at Object>Transform are modal. I'm talking about "Move…", "Rotate…", "Reflect…", and so forth. These dialogs, when open, lock the user out of any interaction with the artboard other than the "preview" button, until the dialog is closed.
    Even more problematically, they lock the scroll and zoom factor of the current user view, so that there's no way to inspect how a precise numeric adjustment affects a part of the layout outside the current window (or within the current window but very small inside it) without committing the change, inspecting it, and then later undoing if necessary. This creates cycles of tedious user adjustments (especially on small monitors) that really should be possible in one user step, by toggling the preview button on and off, and zooming/scrolling.
    This is contrary to most modern UI design principles, which suggest avoiding modes unless they are truly and meaningfully necessary. I don't think this is one of those cases. Photoshop made dialogs for adjustment layers non-modal with CS4, and while there are issues with the newer interface (see John Nack's Configurator workaround), I think it's a win overall. Illustrator needs to catch up in this regard. I realize there is some pretty serious refactoring involved to do this, but it has to be do-able.
    In the words of Larry Tesler's immortal Subaru license plate: "NO MODES"!

    ...make the "transform" dialogs non-modal...
    What, and bring Illustrator out of the 1980s?! Are you mad, man?
    Just so you know you're not alone; I've been complaining about AI's archaic dependency upon modal dialogs for many years.
    ...I'm fully aware of the Transform panel...observing that there's another way to do it...doesn't really address any of my points here...
    But it's not "another way to do it," because the functionality is not the same. The modal dialogs include crucial functionality that cannot be done in the Transform palette. For example, moving something in terms of distance and direction (diagonally), instead of merely by lame X and Y factors. Or transforming about an off-object center of transformation, rather than merely by the 9-point proxy.
    ...the "preview" isn't updated on keyboard entry, and the "preview" checkbox need to be manually toggled on and off...
    But the preview does refresh (and does not have to be toggled) in response to keyboard entry if that keyboard entry is by the arrow keys. For example: Select something, doubleClick the Scale tool, click your cursor in the Uniform value field, and tap the up/down arrow keys (or press and hold them). The value will increment and the preview will update with each key tap. (Be sure to teach that to your students.)
    That does not, of course, negate the complaint, but it does ameleorate it somewhat. The increments are preset; there are no preference settings for them. (Don't even get me started on preferences that should be doc-specific settings, and vice-versa).
    Nor does the valid point that problematic dialogs abound beyond just those associated with the transform tools, but I do agree with it. For just one of many examples, it's nothing short of idiotic that the Scale fields of Transform Each do not have a uniform scaling lock, and that only percentage fields are provided and no explicit dimension fields. Illustrator is quite saturated with such inconsistencies and half-baked implementations.
    But...you're often arguing with the emotionally attached Illustrator devoted here. So I wouldn't recommend holding your breath. It would probably be more effective teaching Illustrator's shortcomings to your beginning students. Probably one of the easiest ways to explain the problem of modal dialogs is to point out that you can't change the current selection with the dialog open.
    JET

  • Non Modal Window Popup BSP View

    Hi,
    I have a requirement to launch a pop up window which will allow the user to access the original screen from which the pop up was launched (i.e. a non modal window). The pop up window contains a calculator with the intention being that the user would be able to view and copy data displayed on the original screen into the fields of the calculator.
    I have created the calculator as a form view within a BSP component. All of the fields on the form view have been configured using the configuration tab. I have successfully created a modal pop up using the following on the buttons click event:
    comp_controller->window_manager->create_popup( ).
    However, this does not meet my requirement because the form view is displayed in a modal window. I have also attempted to load the pop up using javascript however the view does not initialise correctly when it is loaded which causes a null reference error.
    Can anyone please provide any advice or assistance related to creating a non-modal window for a configured form view within a BSP component? Many of the examples I have found online are related to WebDynPro applications and html pages with flow logic rather than configured views with a controller class.
    Thank you.

    Hi,
    I have a requirement to launch a pop up window which will allow the user to access the original screen from which the pop up was launched (i.e. a non modal window). The pop up window contains a calculator with the intention being that the user would be able to view and copy data displayed on the original screen into the fields of the calculator.
    I have created the calculator as a form view within a BSP component. All of the fields on the form view have been configured using the configuration tab. I have successfully created a modal pop up using the following on the buttons click event:
    comp_controller->window_manager->create_popup( ).
    However, this does not meet my requirement because the form view is displayed in a modal window. I have also attempted to load the pop up using javascript however the view does not initialise correctly when it is loaded which causes a null reference error.
    Can anyone please provide any advice or assistance related to creating a non-modal window for a configured form view within a BSP component? Many of the examples I have found online are related to WebDynPro applications and html pages with flow logic rather than configured views with a controller class.
    Thank you.

  • How to display non modal dialog box in a Dll call from TestStand implemented in visual c

    Dear Jason F.
    Applications Engineer
    National Instruments
    Hello
    I did the same way you told me
    the non modal dialog appeared and
    system hangs and
    giving the error message
    ""SeqEdit.exe-Application Error
    The instruction at �0x047fc5b0� referenced memory at �0x047fc5b0�. The memory could not be �read� ""
    please solve my problem
    and thanks for yours early response
    you can email me at
    [email protected]

    Hi Mkehret,
    Does your dialog have ActiveX controls on it? If your DLL dialog uses ActiveX controls and is not programmed in a certain manner it can hang because of a conflict in the threading model used by the TestStand Engine that is calling into your DLL and the model that is required by the MFC ActiveX Container. If you are using ActiveX controls in your dialog, you need to make special considerations for the threading model MFC dialogs that use ActiveX controls need in order to work properly. The example under \Examples\MFCActiveXContainerDlg illustrates how to appropriately handle this situation as well as explaining why it is necessary.
    Note: The above example displays the dialog as modal, but this is irrelevant to the problem I am describing.
    Again for information on properly creating a dialog class object and displaying it as non-modal refer to the information on MSDN that I referred you to in this post:
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000E98A0000&USEARCHCONTEXT_CATEGORY_0=_8_&USEARCHCONTEXT_CATEGORY_S=0&UCATEGORY_0=_8_&UCATEGORY_S=0
    If your dialog does not use ActiveX controls or after trying the programming method illustrated in the "MFCActiveXContainerDlg" example TestStand still hangs when calling your DLL, try calling your DLL from another environment just to make sure whether the DLL works at all. If the DLL works properly when called by another environment (e.g. VB, VC++, LabVIEW, or CVI), please submit a MINIMAL and REPRODUCEABLE example source project for your DLL for us to look at (please exclude all unnecessary code not required to reproduce the specific problem of displaying the dialog, and include all files necessary to build your dll with any
    specific instructions needed to do so).
    Jason F.
    Applications Engineer
    National Instruments
    www.ni.com/ask

  • Problem with non modal ADM dialog

    I have problem with focus and mouse and keyboard event passing to non modal dialog if some modal window was opened and closed on Windows platform.
    I have this problem in my plugin, but also I did some tests with SDK WordFinder Plugin.There are 2 dialogs open there : CountDialog-non modal dialog and PromtDialog-modal one. I commented all lines in function DeleteCountDialog to leave this dialog on the screen. So, first, when "create page map" menu is selected, CountDialog is appearing and stays on the screen. At this stage, it can be moved and get focus when is clicked.After that, I click on "find word by word offset" and then PromtDialog is appearing. when I close Promtdialog by clicking on OK or Cancel, CountDialog is "freezing" - means, it can not be moved and does not get focus when I click on it.
    Is it known problem ? Is there is some workaround there ?
    thanks in advance,
    Lidia.

    Thanks a lot for your response.
    I did changes as you recommended, but still have the same result.
    So I have WordFinder from Acrobat SDK 8 with only one file changed:WordFinderDlg.cpp - see below.The result is the same:
    1. I open Acrobat->Open some file
    2. Click on "Advanced->Acrobat SDK->Word Finder->create Page Map" menu
    3. "count" non Modal Dialog is opened and working and then stays on the screen and can be moved without problem.
    4. Now I click on "Advanced->Acrobat SDK->Word Finder->find Word By Offset" - Modal Promt Dialog is opened. click some number and then click ok - choosen word is selected in Acrobat. From this moment, first "Count" dialog is frosen - can be selected, can not be moved.
    The only workaround I see here is to create non Modal dialog every time I close Modal one.
    Could you please advice ? May I please send to you project in zip ?
    I really need it ASAP ?
    thanks in advance,
    Lidia.
    ADOBE SYSTEMS INCORPORATED
    Copyright (C) 1994-2006 Adobe Systems Incorporated
    All rights reserved.
    NOTICE: Adobe permits you to use, modify, and distribute this file
    in accordance with the terms of the Adobe license agreement
    accompanying it. If you have received this file from a source other
    than Adobe, then your use, modification, or distribution of it
    requires the prior written permission of Adobe.
    \file WordFinderDlg.cpp
    - Implements a modeless progress dialog and a generic prompt dialog.
    // Acrobat headers
    #ifdef WIN_PLATFORM
    #include "PIHeaders.h"
    #endif
    #include "ADMAcroSDK.h"
    #include "resource.h"
    Constants/Declarations
    static ADMDialogRef countDialog;
    static AVWindow gAVWindow = NULL;
    // Global variables used for simplicity
    const ASInt32 MaxLen = 80;
    static char textStr[MaxLen];
    static char titleStr[MaxLen];
    static char msgStr[MaxLen];
    Modeless Progress Dialog
    /* UpdateCountDialog
    ** Updates the dialog with a new GUI function to show count number
    void UpdateCountDialog(ASInt32 cnt)
    ADMItemRef itemRef;
    itemRef = sADMDialog->GetItem(countDialog, IDC_COUNT);
    sADMItem->SetIntValue(itemRef, cnt);
    sADMDialog->Update(countDialog);
    /* CreateCountDialog
    /** GUI function to delete the count dialog
    void DeleteCountDialog(void)
    // destroy dialog
    /*if (countDialog) {
    sADMDialog->Destroy(countDialog);
    countDialog = NULL;
    // Release ADM
    ADMUtils::ReleaseADM();*/
    /* SettingsCountDialogOnInit
    ** Called to initialize the the dialog controls
    ASErr ASAPI CountDialogOnInit(ADMDialogRef dialogRef)
    ADMItemRef itemRef;
    itemRef = sADMDialog->GetItem(dialogRef, IDC_COUNT);
    sADMItem->SetUnits(itemRef, kADMNoUnits);
    sADMItem->SetIntValue(itemRef, 0);
    return kSPNoError;
    /* CreateCountDialog
    ** Creates the modeless dialog.
    void CreateCountDialog(void)
    // Initialize ADM.
    ADMUtils::InitializeADM();
    // Display modeless dialog.
    countDialog = sADMDialog->Create(sADMPluginRef, "ADBE:Wordfinder", IDD_COUNT_DIALOG,
    kADMNoCloseFloatingDialogStyle, CountDialogOnInit, NULL, NULL);
    Generic Prompt Dialog
    /* PromptOnOK
    ** Called when the user clicks OK. Stores the string entered by the
    ** user.
    static void ASAPI PromptOnOK(ADMItemRef item, ADMNotifierRef inNotifier )
    sADMItem->DefaultNotify(item, inNotifier);
    // get user input string
    ADMDialogRef dialog = sADMItem->GetDialog(item);
    ADMItemRef item1 = sADMDialog->GetItem(dialog, ID_PROMPT_FIELD);
    sADMItem->GetText(item1, textStr, MaxLen);
    sADMDialog->EndModal(dialog,IDOK,FALSE);
    AVAppEndModal();
    AVWindowDestroy(gAVWindow);
    /* PromptDialogOnInit
    ** Called to initialize the dialog controls.
    ASErr ASAPI PromptDialogOnInit(ADMDialogRef dialogRef)
    gAVWindow = AVWindowNewFromPlatformThing (AVWLmodal, AVWIN_WANTSKEY, NULL, gExtensionID, sADMDialog->GetWindowRef(dialogRef));
    AVAppBeginModal (gAVWindow);
    sADMDialog->SetText(dialogRef, titleStr);
    sADMDialog->SetDefaultItemID(dialogRef, IDOK);
    sADMDialog->SetCancelItemID(dialogRef, IDCANCEL);
    ADMItemRef itemRef;
    itemRef = sADMDialog->GetItem(dialogRef, IDOK);
    sADMItem->SetNotifyProc(itemRef, PromptOnOK);
    itemRef = sADMDialog->GetItem(dialogRef, ID_PROMPT_FIELD);
    sADMItem->SetUnits(itemRef, kADMNoUnits);
    sADMItem->SetMinIntValue(itemRef, 1);
    itemRef = sADMDialog->GetItem(dialogRef, ID_PROMPT_NAME);
    sADMItem->SetText(itemRef, msgStr);
    return kSPNoError;
    /* PromptForInfo
    /** Generic prompt dialog that gets a text string from the user.
    /** @return IDOK or IDCANCEL.
    ASInt32 PromptForInfo(const char *title, const char *msg, char *buf, ASInt32 bufLen)
    if (!buf || (bufLen == 0))
    ASRaise (GenError(genErrBadParm));
    // Initialize ADM.
    ADMUtils::InitializeADM();
    // init data
    buf[0] = 0;
    strncpy(titleStr, title, sizeof(titleStr) - 1);
    strncpy(msgStr, msg, sizeof(msgStr) - 1);
    // Dispaly modal dialog to get user input
    ASInt32 rc = sADMDialog->Modal(sADMPluginRef, "ADBE:Wordfinder", IDD_PROMPT_DIALOG,
    kADMModalDialogStyle, PromptDialogOnInit, NULL, NULL);
    // get user input data
    if (rc==IDOK)
    strcpy(buf, textStr);
    // Release ADM
    ADMUtils::ReleaseADM();
    return rc;

  • A non-modal, but "always on top" JDialog

    Hi everyone,
    In an applet I am creating, I need to create a non-modal JDialog which stays on top whenever its open. The reason this JDialog is required to be non-modal is that I need the main applet window to be able to react to events and reflect changes in the non-modal JDialog.
    I was wondering how this can be achieved.
    To summarize the problem:
    How can you have a JDialog whose modal property is "false", but stays on top of the applet window.
    This problem has been bugging me for quite a while now, so any pointers will be appreciated.
    Thanks,
    Alan

    Here is how you do it in an applet (as opposed to JApplet):
    * Browser sniffer *
          boolean isNN4=false,isNN6=false,isIE=false;
          Frame F;
          JSObject window=JSObject.getWindow(this);
          JSObject document=(JSObject)window.getMember("document");
          String tmp=document.getMember("all").toString();
          if (tmp.equals("undefined")) {
             tmp=document.getMember("getElementById").toString();
             if (tmp.equals("undefined")) isNN4=true;       // Netscape Navigator 4
             else isNN6=true;                               // Netscape Navigator 6
          } else isIE=true;                                 // MS Internet Explorer
          if (isIE) {
             F=new Frame();
          } else F=(Frame)getParent();
    now you have a frame for use with the Dialog (not JDialog) method
    ...Just add the code shown above in the init method of your applet.
    Good Luck!
    ;o)
    V.V.

  • Non-modal JFileChooser?!...

    hi! i have ds problem.. how do u create a JFileChooser dialog that would only
    be modal to its parent window and not to the entire application window...
    pls. help.. =)

    If the chooser has a JDialog object as a parent component, you can get that object by some method in SwingUtilties, I think... then call setModal on it. But this will make it fully non-modal to all windows. You can't be selective about modal windows without some lower level system tweaking, I think. But generally, a file chooser is modal because usually you can't continue what you are doing til you pick a file or cancel.

  • Change a modal JDialog to non-modal JDialog

    I created a modal JDialog initially, for some result i need change it to a non-modal JDialog, is there any set modal command can do it??

    Nope.
    The reason is because of program flow:
    System.out.println("first line");
    JDialog dialog = new JDialog(modal);
    dialog.setVisible(true); // blocks this flow if and only if modal is true
    System.out.println("second line");
    Try putting a button in the dialog which prints out "button pressed".
    If you press the button each time before closing the dialog you will get:
    when modal is true:
    first line
    button presed
    second line
    when modal is false:
    first line
    second line
    button prese

  • JButton on XP non-modal Jdialog doen't work.

    I recently upgraded from 1.3 to 1.4 while upgrading my OS from NT 4.0 to XP.
    In a stand-alone application I have non-modal JDialog's that are launched as threads so that I can have multiple instances of them running simultaneously. There are JButton's on the JDialog's which no longer respond to any mouse events even though I can execute them via the keyboard using the tab and enter keys. They work just fine under 1.3 or if I make them modal.
    Any thoughts?

    Hello,
    Issue is-
    There are JButton's on the JDialog's which no longer respond to any mouse events even though I can execute them via the keyboard using the tab and enter keys. They work just fine if I make them modal.
    Plz suggest

  • Enabling non-modal JDialog

    I have created a JDialog which is non-modal. This dialog has lot of controls viz. buttons, combo box etc. This dialog is launched on clicking a button placed on panel. Surprisingly, when the dialog is launched, all components are disabled. Is there any way I can make these enabled? There is no line of code which has been done to change the behaviour of these components. They work fine if I make the dialog modal. Please advice.

    Thanks.
    The constructor for creating the dialog is pasted as below:
    public AbstractDialog(Frame owner, String title, boolean isModal) {
              super(owner, title, isModal);
              JRootPane rootPane = getRootPane();
              Action escapeKeyAction = new AbstractAction() {
         public void actionPerformed(ActionEvent e) {
         AbstractDialog.this.dispose();
              rootPane.registerKeyboardAction( escapeKeyAction,
    KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ),
    JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
              UFSAFocusTraversalPolicy obj = new UFSAFocusTraversalPolicy ();
              //obj.setImplicitDownCycleTraversal(false);
              this.setFocusTraversalPolicy(obj);
              this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
         this.setFocusCycleRoot(true);
         this.addWindowListener(windowAdapter);
    The isModal passed is false.

  • 1. Non-modal popup or 2.minimize button on titlebar of popup

    Hi All,
    Firstly, is it now possible to open non-modal pop-ups ( as many pop-ups after executing an action method :( ) , or has anyone come across this found a work-around for this ?
    currently, I am opening a modal dialog itself. But when I click the minimize ( since minimize, maximize and close buttons are activated in the title bar ), the popup minimizes and maximises immediately. This is now raised as a bug and I need to find a solution for this.
    Would much appreciate help,comments or views on this ?
    -- Urvi

    Gor_Mahia wrote:
    ok i got what you mean but its an option for ver1.0 not version 2.0 of the same plugin..thanks.Well, this is an option in the Apex framework for dynamic actions. In Apex 4.2, the options for "Event Scope" are Static, Dynamic and Once.
    In your case, you can set it to live.

  • Non-modal JDialog hides its JFrame "owner"

    I'm writing my first significant swing application. It has a JFrame that launches a JDialog. When constructing the JDialog, I have the JFrame as the owner and set it to be non-modal. The dialog is indeed non-modal, since it allows me to click on the JFrame and run it. However, if the two windows overlap, the JDialog is always on top, covering the JFrame, even if the JFrame has focus. This can make it difficult to effectively work with the JFrame while the JDialog is on the screen.
    There must be a simple solution to this, but I haven't discovered it yet. Any ideas?

    Thank you so much for your reply. I just confirmed that passing null to the JDialog does indeed allow the JFrame to overlay it. However, now if I minimize the JFrame, the JDialog stays up. I'd prefer that it go disappear with the JFrame. Is there a way to "have it both ways"? That is, Is there a way to make the JDialog go away when the JFrame is minimized, but still make it possible for the JFrame to overlay the JDialog?
    Thanks again for the original reply.
    TIA on this one, too!
    Tim

  • Non modal JDialog

    Hi All,
    I want a non modal JDialog which is used to show the message to the user that it is searching for the records, when a search is performed and records are retrieved from the database. When the search is going on user might hit cancel on the JDialog to cancel the search. My problem is, the cancel button on the Search dialog is not catching the event and user is not able to select the cancel option on the dialog.
    Here is my code :
    class SearchWindow extends JDialog {
    private JPanel btnPanel;
    private JLabel lblSearch;
    private JButton btnCancel;
    * Constructor
    public SearchWindow() {
    super((Frame)null, false);
    setTitle("Searching Shipment Legs");
    cancelled = false;
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent evt) {
    close();
    Container contentPane = getContentPane();
    contentPane.setLayout(null);
    addButtons();
    pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(new Dimension(300, 100));
    setSize(300,100);
    setLocation((screenSize.width-700)/2,(screenSize.height-450)/2);
    private void addButtons() {
    btnPanel = new JPanel();
    btnPanel.setLayout(new BorderLayout());
    lblSearch = new JLabel("Searching..........");
    btnCancel = new JButton("Cancel");
    btnPanel.setBackground(Color.lightGray);
    lblSearch.setBackground(Color.lightGray);
    btnCancel.setBackground(Color.lightGray);
    btnPanel.add(lblSearch, BorderLayout.CENTER);
    btnPanel.add(btnCancel, BorderLayout.SOUTH);
    btnCancel.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent evt) {
    System.out.println("cancel");
    cancelled = true;
    close();
    btnPanel.setBounds(0,0,200,50);
    this.getContentPane().add(btnPanel);
    lblSearch.setVisible(true);
    btnCancel.setVisible(true);
    this.getContentPane().validate();
    public void close() {
    this.setVisible(false);
    this.dispose();
    public void show() {
    super.show();
    paintComponents(getGraphics());
    this.setModal(false);
    Any help is greatly appreciated.
    Thanks,
    Bhaskar

    Hi Haroldsmith
    I am calling this search window in one of my programs where on button click it will fetch the records from the database. When this process is on, search dialog is shown up. Ths dialog is shown correctly and its getting closed as soon as the search is completed. But the probelm is its not allowing me to click on cancel button.
    Bhaskar

  • Imitate modal dialog by non-modal

    Hi
    I'm trying to achieve modal dialog functionality by non-modal (i have reasons to do that), but I have encountered a real problem:
    calling wait() from EDT is freezing everything. Below is source code, in most cases dialog is created inside action listener (in the EDT), so it is the source of problem:
    public class TestMyDialog {
         public TestMyDialog() {
              final JFrame jFrame = new JFrame();
              JPanel panel = new JPanel();
              JButton button1 = new JButton("open dialog");
              JButton button2 = new JButton("close");
              button1.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        System.out.println(SwingUtilities.isEventDispatchThread());
                        Object syncObject = new Object();
                        new MyDialog(jFrame, "title", syncObject);
                        try {
                             synchronized (syncObject) {
                                  syncObject.wait();
                        } catch (InterruptedException ex) {
                             ex.printStackTrace();
                        System.out.println("dialog closed");
              button2.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        System.exit(0);
              panel.add(button1);
              panel.add(button2);
              jFrame.getContentPane().add(panel);
              jFrame.setUndecorated(true);
              jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              jFrame.pack();
              jFrame.setVisible(true);
         public static void main(String[] args) {
              new TestMyDialog();
    }And main class:
    * Dialog that imitates modal dialog.
    * @author ggg
    @SuppressWarnings("serial")
    public class MyDialog extends JDialog {
         private Frame ownerFrame;
         public MyDialog(Frame owner, String title, final Object syncObject) {
              super(owner, title, false); // modal = false
              this.ownerFrame = owner;
              JButton button1 = new JButton("close dialog");
              button1.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        ownerFrame.setFocusable(true);
                        ownerFrame.setEnabled(true);
                        setVisible(false);
                        dispose();
                        synchronized (syncObject) {
                             syncObject.notifyAll();
              add(button1);
              ownerFrame.setFocusable(false);
              ownerFrame.setEnabled(false);
              setSize(300, 200);
              setVisible(true);
         } // end of constructor
    }Any ideas would be highly appreciated.

    gimbal2 wrote:
    calling wait() from EDT is freezing everything.
    Any ideas would be highly appreciated. What about... don't ever block the EDT?Why do you mean by don't block the EDT? I'm using wait() because I need the calling thread to stop for a while (close dialog) but unfortunately this thread is EDT in case of ActionListeners....
    AndrewThompson64 wrote:
    gregory_33 wrote:
    ..I'm trying to achieve modal dialog functionality by non-modal (i have reasons to do that), ..What are those reasons?It was requirements from my boss, and please don't ask me why.... I just have to try to solve this.
    And thanks for interest for all of you.

Maybe you are looking for