Non-modal JDialog is not painted and blocks the GUI

I have developed a GUI that's basically a JFrame with a JDesktopPane.
The user can, via a menu item, pop up a JDialog that contains some JLists and then select some value from it. Once he/she has done the selection and clicks on OK, the dialog disappears (data processing is then done in the main GUI) and comes back once a specific event has happened. The user then selects other data and so on, until he/she clicks on Cancel, which definitely disposes of the JDialog.
The graphics of the JDialog are build in the class constructor, which does a pack() but does not make the dialog visible yet. The dialog appears only when doSelection() is called.
     /** Called the first time when user selects the menu item, and then
     when a specific event has happened. */
     public Data[] doSelection() {
          dialog.setVisible(true);
          // ... Code that reacts to user's input. Basically, the ActionListener
          // added to the buttons retrieves the user's selection and calls
          // dialog.setVisible(false) if OK is clicked, or calls dialog.dispose()
          // if Cancel is clicked.
     }Now, everything works fine if the JDialog is modal, but if I make it non-modal only the window decorations of the JDialog are painted, and the control doesn't return to the main GUI. Calling doLayout() or repaint() on the doSelection() has no effect. How can this be fixed?
I hope I have been able to explain the problem satisfactorily, I could not create a suitable SSCCEE to show you. Thanks in advance for any hint.

Ok, I've taken some time to think about this problem and I've modified the code a bit.
Now the dialog shows itself and is responsive (i.e. its JLists can be operated), but the Ok button does not close the dialog as I'd want. I believe that I'm messing up things about threading, and the operations in actionPerformed() should be carried out in another thread, if possible.
Thanks in advance for any hint / suggestion / comment / insult.
     private Data[] selection;
     /** Constructor */
     public MyDialog() {
          // ... Here is the code that builds the dialog...
          dialog.setModal(false);
          dialog.pack();
          // Note that the dialog is not visible yet
     public Data[] doSelection() {
          operatorAnswer = NONE_YET;
          dialog.setVisible(true);          
          while (operatorAnswer == NONE_YET) {
               try {
                    wait();
               } catch (InterruptedException e) { }
          return (operatorAnswer == OK ? selection : null);
     public void actionPerformed(ActionEvent evt) {
          if (okButton.equals(evt.getSource())) {
               operatorAnswer = OK;
               retrieveSelection();
               dialog.setVisible(false);
          else if (cancelButton.equals(evt.getSource())) {               
               operatorAnswer = CANCEL;
               dialog.dispose();
     private void retrieveSelection() {
          // ... Here is the code that retrieves selected data from the dialog's JLists
          // and stores it in the "selection" private array...
          notifyAll();
     }

Similar Messages

  • 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

  • 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

  • Is there a way to display a  non modal JDialog on JApplet

    Whenever I try to add a non modal JDialog over a JApplet, the JDialog freezes and components on it never gets painted. After a disappointing search over web, I've kinda begin to hate swing. I am shocked that a very basic thing like this is so hard to achieve in Java. Any solution folks?
    My code is as follows:
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    public class DialogApplet extends JApplet {
         private javax.swing.JPanel jContentPane = null;
         private JButton jButton = null;
          * This method initializes jButton     
          * @return javax.swing.JButton     
         private JButton getJButton() {
              if (jButton == null) {
                   try {
                        jButton = new JButton();
                        jButton.setText("Click Me"); 
                        jButton.setBounds(75, 80, 147, 34); 
                        jButton.addActionListener(new java.awt.event.ActionListener() {
                             public void actionPerformed(java.awt.event.ActionEvent e) {   
                                  Frame f = javax.swing.JOptionPane.getFrameForComponent(jContentPane);
                                  JDialog pi = new JDialog(f, "MainFrame Dialog", false);
                                pi.getContentPane().add(new JLabel("I got to be working Bossie!!!"));
                                pi.pack();
                                pi.setLocation(75, 80);
                                pi.setVisible(true);
                                try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                                pi.setVisible(false);
                   catch (java.lang.Throwable e) {
                        e.printStackTrace();
              return jButton;
         public static void main(String[] args) {
          * This is the default constructor
         public DialogApplet() {
              super();
              init();
          * This method initializes this
          * @return void
         public void init() {
              this.setSize(300,200);
              this.setContentPane(getJContentPane());
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private javax.swing.JPanel getJContentPane() {
              if(jContentPane == null) {
                   jContentPane = new javax.swing.JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJButton(), null); 
              return jContentPane;
    }

    try this, it is really simple, just to look at
    example from the swing tutorials.
    Thanks my friend, If you carefully observe my code, I also needed some piece of code to run in the background ((The thread.sleep() part)) while displaying the dialog. The problem was the JDialog used to freeze and components on it never used to get painted. Finally I managed to find a way out. If we try to display a JDialog with a new thread, The event dispatching thread takes precedence and the painting of components on the JDialog happens only after even dispatching thread is done. All I did was display JDialog in the event dispatch thread and run the background process in new thread.
    My code.
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class DialogApplet extends JApplet {
        private javax.swing.JPanel jContentPane = null;
        private JButton jButton = null;
        private JDialog dialog = null;
         * This is the default constructor
        public DialogApplet() {
            super();
            init();
         * This method initializes this
        public void init() {
            this.setSize(300, 200);
            Container container = this.getContentPane();
            container.add(getJContentPane());
         * This method initializes jContentPane
         * @return javax.swing.JPanel
        private javax.swing.JPanel getJContentPane() {
            if (jContentPane == null) {
                jContentPane = new javax.swing.JPanel();
                jContentPane.setLayout(null);
                jContentPane.add(getJButton(), null);
            return jContentPane;
         * This method initializes jButton
         * @return javax.swing.JButton
        private JButton getJButton() {
            if (jButton == null) {
                try {
                    jButton = new JButton();
                    jButton.setText("Click Me");
                    jButton.setBounds(75, 80, 147, 34);
                    jButton.addActionListener(new java.awt.event.ActionListener() {
                            public void actionPerformed(java.awt.event.ActionEvent e) {
                                showDialog();
                } catch (java.lang.Throwable e) {
                    e.printStackTrace();
            return jButton;
         * This method displays Dialog
        public void showDialog() {
            final Frame frame = JOptionPane.getFrameForComponent(this);
            dialog = new JDialog(frame, "DialogApplet", false);
            dialog.setModal(true);
            Container contentPane = dialog.getContentPane();
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JLabel("I got to be working Bossie!!!"), BorderLayout.CENTER);
            contentPane.add(panel);
            dialog.pack();
            Thread t = new Thread() {
                    public void run() {
                        for (int i = 0; i < 100000; ++i) {
                            System.out.println(i);
                        dialog.hide();
            t.start();
            dialog.show();
    }

  • 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

  • DB Diagram: Modality Difference between NOT NULL and check constraint

    Hi,
    I am using jdev 11g (11.1.1.10) I am trying to create a db diagram from two tables. I have a FK that is NOT NULL (defined on the column). When i try to display these two tables modality, it does not show up in the diagram. I noticed that there are two ways NOT null can be defined on a table (right click on the db object to edit it; a) under column definitions there is a check box for not null, b) there is a check constraint that one can add to do not null.
    I am confused and was wondering whether I must I have check constraints on the database in order to display modality (optional versus mandatory). Logically speaking it does not make any sense though.

    Hi Susan,
    Thanks for your email. I understand that in order to show modality under
    UML notation, one must define a COLUMN being NOT NULL instead of defining a check constraint.
    I still do not understand how modality (optional versus mandatory) is shown in ERD notation in JDev. I tried flipping ERD/UML notations and made sure icons for tables were showing, but no MODALITY is shown in ERD notation ( an '0" icon or a "|" icon for optional and mandatory). Is it the solid line versus dotted line in the ERD diagram? I am confused because generally under Crawfoot ERD notation '0" icon or a "|" icon is shown for modality.
    Modality gets picked up in jdev diagram when COLUMN not null is specified and UML notation is used
    ALTER TABLE DETAILAJ MODIFY EMPID not null;
    Modality does not get picked up in jdev db diagram when check constraint is specified and UML notation is used
    ALTER TABLE DETAILAJ
    ADD CONSTRAINT CK_NN_DETAILAJ__EMPID CHECK(EMPID IS NOT NULL) ;
    Another question i have related to the matter mentioned above is as follows. Since I want to see modality in db diagram, it follows that I must define a column as not null instead of a check constraint. I must also use NO VALIDATE on NOT NULL column because i have prior data that does not meet the new restriction. I noticed that if i use the following syntax to define a NOT NULL column, two things happen.
    a) A constraint is defined as not null automatically and a system generated name is given to the constraint.
    b) DB diagram in Jdev does not show the modality.
    My question is whether there is a way to see modality in this case.
         alter table DETAILAJ
         MODIFY EMPID NOT NULL ENABLE NOVALIDATE ;
    Edited by: user11219846 on Nov 19, 2009 11:07 AM

  • Hi I'm new to Mac. I have a macbook air and for some reason the top keys, ec, f1 etc etc are not functioning and emitt the non function noise when pressed. Also the volume keys don't adjust the volume. Have I done something to disable them?

    Hi I'm new to Mac. I have a macbook air and for some reason the top keys, ec, f1 etc etc are not functioning and emitt the non function noise when pressed. Also the volume keys don't adjust the volume. Have I done something to disable them?

    I don't have the same version of OS X here but try System Preferences>Keyboard. Is there an option similar to "Use the F1, etc, keys as standard function keys"?
    If so, and it has a checkmark, uncheck it & see if that does the trick.
    ~Lyssa

  • Customer Standard Order was delivered with credit status not approved and blocked.

    The Customer Standard Order was delivered with the credit status not approved and blocked.
    3 orders were delivered without credit limit and now the credit limit is exceed in more than 250%,
    We have checked the settings in OVAK and the assignment is correctly set as D and 01. This is an issue with a high risk customer with static check in OVA8 transaction.
    Please advice.
    BR
    Anuja

    The Customer Standard Order was delivered with the credit status not approved and blocked.
    If the sales order is blocked system can not allow you to create delivery with out approving it.
    3 orders were delivered without credit limit and now the credit limit is exceed in more than 250%
    There could be reason that in FD32 for the payer customer the risk category might not have been assigned during those 3 sales orders creation. Also one more reason in OVA8 against the Static credit check if open order field is not ticked.
    Please let me understand what is your exact issue currently?
    thanks,
    Srinu.

  • On previous iPhones you could go to settings and block the the actual text message from pooping up. Only the sender would show up. On the i4gs the sender and message show up. This is a major flaw as far as privacy. There are no options with in settings to

    On previous iPhones you could go to settings and block the the actual text message from pooping up. Only the sender would show up. On the i4gs the sender and message show up. This is a major flaw as far as privacy. There are no options with in settings to stop this from happening. PLEASE TELL ME IM WRONG ???

    YOU ARE WRONG.
    Go to Settings > Notifications > Messages. You can turn Notifcation Center off for Messages, or select None for the alert style, and turn Show Preview off, and view in Lock Screen on or off.

  • The LOV modal window could not return value to the base page

    when practicing the "create1" task in tutorial, met an issue.
    when create an employee, manageName is a messageLovInput and managerID is a messageTextInput.
    The issue is the LOV modal window could not return value to the mangerName, but can return to managerID .
    If I remove the data boud porperties of the managerName (the bc4j porperties of view name-EmpFullVO and view attribute-MgrName), the lov works fine.
    What is the reason?

    James I would suggest to read the LOV topic in OAF developers' guide. Lov mappings are responsible for bringing pop up values to base page in LOV.
    --Mukul                                                                                                                                                                                                                                                                                                                                                   

  • Acrobat 7 mandatory update failing with error 16820 and blocking the use of the program

    Acrobat 7 mandatory update failing with error 16820 and blocking the use of the program

    Sorry I can't get the screen print to upload
    It says
    Mandatory Update Available
    A Mandatory version of this application is available for download. Application can't continue without installing this version.
    Application:     Acrobat_com
    Installed version: 2.0.0.0
    Update Version : 2.3.0.0
    Download now                    Quit
    Release notes ( this is blank)
    After selecting 'Download Now' I get the following message;
         Download failed
         There was an error downloading the update. Error #16820
         Close

  • Allow same skype contacts and block the rest

    Hi,
    I need allow specific skype contacts and block the rest, is it possible?
    Thanks
    Diego Riera | Linkedin |
    Twitter |
    diegoriera.wordpress.com
    Por favor, lembre-se de clicar em "Marcar como Resposta" no post que o ajuda, e clique em "Desmarcar como resposta" se um post marcado na verdade não responder a sua pergunta. Isto pode ser benéfico para outros membros da comunidade. Esta
    postagem é fornecida, sem garantias e sem direitos.

    I am not sure these tools will do what you want. Looks like you can manage the contact list, but that would involve removing the contacts they're not supposed to have after they've added them - rather than blocking. 
    You could try this: http://www.colima.de/en/products/simpleroute.html 
    I've not tried it, but one of the listed features is federation control. 
    Matt Landis did a write-up on some options here including the tool above. http://windowspbx.blogspot.com/2012/07/controlling-who-has-what-access-to-who.html
    If this helped you please click "Vote As Helpful" if it answered your question please click "Mark As Answer" | Blog
    www.lynced.com.au | Twitter
    @imlynced

  • My G Drive will not show up on my desktop for use. It did yesterday. It is not full and currently the light turns on and seems to be running but will not show up on my desktop. What can I do?

    My G Drive will not show up on my desktop for use. It did yesterday. It is not full and currently the light turns on and seems to be running but will not show up on my desktop. What can I do?

    1. verify on another Mac first. and another port.
    2. very likely dead SATA card
    read about it here:
    Your dead external hard drive is likely fine! Great hope for your 'faulty' external HD

  • I have apple iPhone 4S upgraded to iOS 6.0.1 and everything was working fine suddenly my Wifi was not connecting and found the wifi on/off button is greyed out and to enable it I tried all resets but still my problem have not solved, still wifi is off

    I have apple iPhone 4S upgraded to iOS 6.0.1 and everything was working fine suddenly my Wifi was not connecting and found the wifi on/off button is greyed out and to enable it I tried all resets but still my problem have not solved, still wifi is off

    Same here.... No fix. Replacing is the option apparently and if you're out of warranty, you're SOL. That was as per the "Genius" at Apple.

  • Images I move from one folder into another are disappearing, at first it was occurring immediately if I did not copy and paste the images. Today however I found out that images I had been using for days just up and vanished from their new location.

    Images I move from one folder into another are disappearing, at first it was occurring immediately and only if I did not copy and paste the images. Today however I found out that images I had been using for days just up and vanished from their new location. A few of these images had copies in another folder that remained and the ones I couldn't find may or may not have ever had copies. I had backed up my system with time machine recently as well, so I went into the backup to retreive the lost images. When I searched and found the backup copies I got the error "the file alias cannot be opened because the original cannot be located". The crazy thing is that the images that remained on my computer did not give me the same error and opened like they should.
    In short images that I am creating, saving, and using are disapearing so epically that even time machine versions are affected when retrieval is attempted. Any suggestions as to what I could be doing wrong without realizing it? Or perhaps other people have had similar bugs that are software related and have a solution?

    Hi Kevin,
    I understand what you tried to do but it doesn't work that way. Swapping drive names will just mess things up.
    You should be able to reconnect the files though: in the Locate Referenced Files dialog make sure you click the Show Reconnect Options button — this will give you access to all the connected drives. Locate one of the files and hit Reconnect All. Should do the trick.
    Best

Maybe you are looking for

  • Af:region, PPR and onload handler

    We develop custom JSF components that need some javascript counterpart on the client. These counterparts needs to be initialized (through some AJAX calls) when the page is ready to be displayed. In old technologies, this was done through an "onload"

  • Help with error

    Hi there, I can not figure out why I keep getting the following message when trying to update a form. Can anyone suggest what it may be? Microsoft JET Database Engine error '80040e14' Syntax error in UPDATE statement. /html/userinfo.asp, line 133 [Co

  • UserTransaction doesn't rollback (JOTM)

    I'm running tomcat 5.5 with SQL Server 2000. I'm working on adding transaction support through UserTransaction with JOTM. I installed JOTM, a Transcation Manager, but it doesn't seem to work. When I try to rollback an update, it still commits it. ###

  • What is the Firefox equivalent of IE8/Tools/Internet Options/trusted sites/sites?

    My new VPN requires I select its server as a "trusted site". I can do this easily on Internet Explorer, but I don't see how to do this on Firefox.

  • Updated IOS 7.0.2 iphone 4s was not able to tethering with Mac using usb. Please anyone got any suggestions.

    I am not able to tether my updated iphone ios 7.0.2, via usb . as i used to tether in old iso 6 version with my mac. does any one got the same problem. pls send me a suggestion if you got any solutons. thanks narthan