Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4122683

hiding modal Dialog on NT can deadlock, freezing GUI

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.1.6
    • 1.1, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.2.0
    • client-libs
    • 1.1.6
    • generic, other, x86, sparc
    • generic, solaris_2.5.1, windows_95, windows_nt
    • Not verified

        eld, "Center");
            JButton browseBtn = new JButton("Browse...");
            browseBtn.addActionListener(
            new ActionListener()
            {
              public void actionPerformed(ActionEvent e)
                {
                  selectMainFile();
                }
            }
            );
            mainClassPanel.add(browseBtn, "East");
            getContentPane().add(mainClassPanel);
            WindowListener wl = new WindowAdapter()
              {
        public void windowClosing(WindowEvent e)
           {
             destroy();
           }
              };
            addWindowListener(wl);
          }
          public void destroy()
          {
            System.exit(0);
          }
          public void selectMainFile()
          {
            File fileObj = null;
            JFrame parent = new JFrame();
            JFileChooser fileDlog = new JFileChooser();
            fileDlog.addChoosableFileType("Class File(*.class)", ".class", null);
            fileDlog.showDialog(parent);
            fileObj = fileDlog.getSelectedFile();
            mainClassField.setText(fileObj.getName());
          }
        }
        --- End TstJFileChooser.java ---
        Steps to produce the hang:
        1. javac -verbose TstJFileChooser.java
        2. java TstJFileChooser
        3. Hit the Browse... button
        4. Choose any file
        The app is now deadlocked. Here is the JVM state at this point:
        Full thread dump:
            "AWT-Dispatch-Proxy" (TID:0x13b14c8,
        sys_thread_t:0xcdc7f0,Win32ID:0x117, state:CW) prio=5
                java.lang.Object.wait(Object.java:315)
        com.sun.java.swing.text.AbstractDocument.readLock(AbstractDocument.java:678)
        com.sun.java.swing.text.AbstractDocument.render(AbstractDocument.java:248)
                com.sun.java.swing.text.DefaultTextUI.paint(DefaultTextUI.java:442)
                com.sun.java.swing.plaf.ComponentUI.update(ComponentUI.java:47)
                com.sun.java.swing.JComponent.paintComponent(JComponent.java:374)
                com.sun.java.swing.JComponent.paint(JComponent.java:579)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JLayeredPane.paint(JLayeredPane.java:396)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:567)
                java.awt.Container.paint(Container.java:702)
                java.awt.Component.dispatchEventImpl(Component.java:1723)
                java.awt.Container.dispatchEventImpl(Container.java:939)
                java.awt.Window.dispatchEventImpl(Window.java:443)
            "TimerQueue" (TID:0x139dee8, sys_thread_t:0xcb9e60, Win32ID:0x12a,state:CW) prio=4
                com.sun.java.swing.TimerQueue.run(TimerQueue.java:249)
                java.lang.Thread.run(Thread.java:474)
            "Screen Updater" (TID:0x139be58, sys_thread_t:0xcbaa80,Win32ID:0xdc, state:CW) prio=4
                java.lang.Object.wait(Object.java:315)
                sun.awt.ScreenUpdater.nextEntry(ScreenUpdater.java:78)
                sun.awt.ScreenUpdater.run(ScreenUpdater.java:98)
            "AWT-Windows" (TID:0x1395368, sys_thread_t:0xcb6600, Win32ID:0x6e,state:R)prio=5
                sun.awt.windows.WToolkit.run(WToolkit.java:106)
                java.lang.Thread.run(Thread.java:474)
            "AWT-EventQueue-0" (TID:0x1395188, sys_thread_t:0xcb6510,Win32ID:0x11a, state:MW) prio=5
                java.awt.Component.invalidate(Component.java:1126)
                java.awt.Container.invalidate(Container.java:485)
                com.sun.java.swing.JComponent.revalidate(JComponent.java:2907)
        com.sun.java.swing.text.DefaultTextUI$RootView.preferenceChanged(DefaultTextUI.java:714)
                com.sun.java.swing.text.View.preferenceChanged(View.java:84)
        com.sun.java.swing.text.PlainView.preferenceChanged(PlainView.java:285)
                com.sun.java.swing.text.PlainView.updateDamage(PlainView.java:458)
                com.sun.java.swing.text.PlainView.insertUpdate(PlainView.java:391)
                com.sun.java.swing.text.FieldView.insertUpdate(FieldView.java:237)
        com.sun.java.swing.text.DefaultTextUI$RootView.insertUpdate(DefaultTextUI.java:834)
        com.sun.java.swing.text.DefaultTextUI$UpdateHandler.insertUpdate(DefaultTextUI.java:1050)
        com.sun.java.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:137)
        com.sun.java.swing.text.AbstractDocument.insertString(AbstractDocument.java:415)
        com.sun.java.swing.text.JTextComponent.setText(JTextComponent.java:1089)
                TstJFileChooser.selectMainFile(TstJFileChooser.java:77)
                TstJFileChooser$1.actionPerformed(TstJFileChooser.java:48)
        com.sun.java.swing.AbstractButton.fireActionPerformed(AbstractButton.java:860)
        com.sun.java.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:895)
        com.sun.java.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:338)
        com.sun.java.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:230)
            "Finalizer thread" (TID:0x1390088, sys_thread_t:0xc9a180,
        Win32ID:0x12c, state:CW) prio=2
            "main" (TID:0x13900b0, sys_thread_t:0xc9b9b0, Win32ID:0x102,state:CW) prio=5
        Monitor Cache Dump:
            sun.awt.ScreenUpdater@139BE58/14033E8: <unowned>
                Waiters: 1
            com.sun.java.swing.text.PlainDocument@139F078/14139F8: <unowned>
                Waiters: 1
            java.lang.Object@1393E00/13DE1B8: owner "AWT-Dispatch-Proxy"
        (0xcdc7f0, 4 entries)
            com.sun.java.swing.TimerQueue@139DEF0/140DA88: <unowned>
                Waiters: 1
        Registered Monitor Dump:
            Thread queue lock: <unowned>
                Waiters: 1
            Name and type hash table lock: <unowned>
            String intern lock: <unowned>
            JNI pinning lock: <unowned>
            JNI global reference lock: <unowned>
            BinClass lock: <unowned>
            Class loading lock: <unowned>
            Java stack lock: <unowned>
            Code rewrite lock: <unowned>
            Heap lock: <unowned>
            Has finalization queue lock: <unowned>
            Finalize me queue lock: <unowned>
                Waiters: 1
            Monitor registry: <unowned>
        _________________________________________
        Subject: Re: Deadlock with Swing 1.0.1
                Date: 11 Mar 1998 14:43:57 GMT
               From: "Anthony" <###@###.###>
         Organization: DIGEX, Inc.
         Newsgroups: comp.lang.java.gui
          References: 1
        This probably explains why every JDialog that I have a JTextfield in
        deadlocks when using setText on them. Is there a workaround. This is with
        Swing 1.0.1 and JRE 1.1.4 and .5
        --
        Anthony
        replace xxx.xxx with his.com to reply
        Dave Hoag <###@###.###> wrote in article
        <6e3gvl$###@###.###>...
        > I've discovered a potential deadlock with the latest version of swing.
        > I'm running swing 1.0.1 with JDK1.1.5.
        >
        > The potential problem can occur when you use a JTextField. The real cause
        > of the problem lies within com.sun.java.swing.text.AbstractDocument and the
        > way it handles 'thread safe' access to a Document.
        >
        > When I issue a set text, this will take out a writeLock on a document.
        > When another thread attempts to read the documents value it attempts to take
        > out a readLock, if there is a currently writeLock, it 'wait()'s until it can
        > safely read the value.
        >
        > Here is the deadlock scenario.
        > On the core java Event thread I push a button that will eventually call a
        > setText on the JTextField. This takes out a writeLock.
        >
        > On the core java Dispatch-Proxy thread, it starts to repaint my screen.
        > When it reaches the JTextField, it waits.
        >
        > When processing the setText on the other thread it eventually fires an
        > InsertUpdate event. Swing's code eventually calls Component.invalidate().
        > Well, to do this it synchronizes on Component.lock. To bad, because it
        > appears that the waiting Dispatch-Proxy thread has this lock. Deadlock
        > occurs. The Dispatch-Proxy thread is waiting on read access to the
        > JTextField and the Event thread is waiting on Component.lock.
        >
        > - Dave Hoag
        > ObjectWave Corp.
        >
        >
        >
        _________________________________________
        Subject: Re: Deadlock with Swing 1.0.1
                Date: Wed, 11 Mar 1998 19:18:00 -0600
               From: "Dave Hoag" <###@###.###>
         Organization: Netcom
         Newsgroups: comp.lang.java.gui
          References: 1 , 2
        This is the response I received from the Swing/AWT team.
        :The problem here is that there are two event threads active at
        :the same time here (something that is NOT supposed to happen).
        :This is a condition that occurs when a modal dialog is brought down.
        Well, that's great, but I'm still without a workaround (aside from changing
        the swing source to not readLock, which is a bad idea) and the damage to the
        credibility of the JFC has been done. I've held others off with statements
        like, "well, you see Swing0.7 is only a beta, so we have to expect
        problems." No matter the source of the problem, the quality of the
        'Official' release has people questioning our choice to use Java.
        Unfortunately, my client now we are to try and use the Microsoft Foundation
        Classes to see if we achieve a higher degree of reliability.
        - Dave
        Anthony wrote in message <01bd4cfb$af20da30$a700000a@guido>...
        >This probably explains why every JDialog that I have a JTextfield in
        >deadlocks when using setText on them. Is there a workaround. This is with
        >Swing 1.0.1 and JRE 1.1.4 and .5
        >--
        >
        >Anthony
        >replace xxx.xxx with his.com to reply
        >
        >Dave Hoag <###@###.###> wrote in article
        ><6e3gvl$###@###.###>...
        >> I've discovered a potential deadlock with the latest version of swing.
        >> I'm running swing 1.0.1 with JDK1.1.5.
        _________________________________________
        Subject: Re: Deadlock with Swing 1.0.1
                Date: 13 Mar 1998 01:07:19 GMT
               From: "David Holmes" <###@###.###>
         Organization: Microsoft Research Institute
         Newsgroups: comp.lang.java.gui
          References: 1 , 2 , 3
        Dave Hoag <###@###.###> wrote in article
        <6e7d72$###@###.###>...
        > This is the response I received from the Swing/AWT team.
        >
        > :The problem here is that there are two event threads active at
        > :the same time here (something that is NOT supposed to happen).
        > :This is a condition that occurs when a modal dialog is brought down.
        >
        So surprise, surprise they have still failed to fix the modal dialog
        problems that plague the AWT.
        David
        _________________________________________
        ***** Thread # 2 ********
        _________________________________________
        _________________________________________
        Subject: JDialog problems
                Date: Mon, 16 Mar 1998 13:25:32 -0600
               From: Michael Monschke <###@###.###>
            Reply-To: ###@###.###
         Organization: MCS
         Newsgroups: comp.lang.java.gui
        I am having problems with the JDialog class on a WinNT 4 machine. If
        you overlap components, the JDialog will hang if modal. It seems to
        hang for other reasons I'm not sure of also. Is anyone having this
        problem?
        This problem does not exist if the dialog is not modal.
        _________________________________________
        Subject: Re: JDialog problems
                Date: 17 Mar 1998 21:36:56 GMT
               From: "John Tracy" <###@###.###>
         Organization: MagicNet, Inc.
         Newsgroups: comp.lang.java.gui
          References: 1
        Michael Monschke wrote in message <###@###.###>...
        >I am having problems with the JDialog class on a WinNT 4 machine. If
        >you overlap components, the JDialog will hang if modal. It seems to
        >hang for other reasons I'm not sure of also. Is anyone having this
        >problem?
        >
        >This problem does not exist if the dialog is not modal.
        >
        We have seen quite a few problems with Swing 1.0.1 modal
        dialogs on Windows NT machines. We have reported them
        to Sun several times with no response.
        We have found that disposing() the dialog after show returns
        helps in some cases. We think it is a timing problem caused
        by Swing having multiple threads drawing at the same time,
        which is not supposed to happen.
        Subject: Re: JDialog problems
                Date: 17 Mar 1998 21:36:56 GMT
               From: "John Tracy" <###@###.###>
         Organization: MagicNet, Inc.
         Newsgroups: comp.lang.java.gui
          References: 1
        Michael Monschke wrote in message <###@###.###>...
        >I am having problems with the JDialog class on a WinNT 4 machine. If
        >you overlap components, the JDialog will hang if modal. It seems to
        >hang for other reasons I'm not sure of also. Is anyone having this
        >problem?
        >
        >This problem does not exist if the dialog is not modal.
        >
        We have seen quite a few problems with Swing 1.0.1 modal
        dialogs on Windows NT machines. We have reported them
        to Sun several times with no response.
        We have found that disposing() the dialog after show returns
        helps in some cases. We think it is a timing problem caused
        by Swing having multiple threads drawing at the same time,
        which is not supposed to happen.
        _________________________________________
        Subject: Re: JDialog problems
                Date: Wed, 18 Mar 1998 09:24:33 +0000
               From: Alexis Moussine-Pouchkine
        <###@###.###>
         Organization: GIE Symphonie
         Newsgroups: comp.lang.java.gui
          References: 1 , 2
        My experience on NT boxes with Swing-1.0.1 and JDialogs is that it
        works best with JDK 1.1.5. NullPointerExceptions and modal dialog
        issues were essentially due to an AWT bug fixed in this release.
        (Of course you sh
        ======================================================================


        Name: mf23781 Date: 03/25/98


        Win 95 4.00.950a
        JDK 1.1.5
        JFC/Swing 1.0
        Hangs occur when a dialog is closed.
        This mostly occurs when using JOptionPane, but also when
        creating a JDialog.
        I believe that all my processing is being done in the event thread,
        as is suggested.
        Occasionally hangs with this small test app. Full application hangs more
        regularly.
        This is a dump from a hung run, followed by the code.
        ________________________________________________________________
        Full thread dump:
            "AWT-Dispatch-Proxy" (TID:0xe7e510, sys_thread_t:0x7dac80, Win32ID:0xfff4f667, state:CW) prio=5
                java.lang.Object.wait(Object.java:315)
                com.sun.java.swing.text.AbstractDocument.readLock(AbstractDocument.java:678)
                com.sun.java.swing.text.AbstractDocument.render(AbstractDocument.java:248)
                com.sun.java.swing.text.DefaultTextUI.paint(DefaultTextUI.java:442)
                com.sun.java.swing.plaf.ComponentUI.update(ComponentUI.java:47)
                com.sun.java.swing.JComponent.paintComponent(JComponent.java:374)
                com.sun.java.swing.JComponent.paint(JComponent.java:579)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JViewport.paint(JViewport.java:266)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
                com.sun.java.swing.JComponent.paint(JComponent.java:582)
                com.sun.java.swing.JLayeredPane.paint(JLayeredPane.java:396)
                com.sun.java.swing.JComponent.paintChildren(JComponent.java:434)
            "Screen Updater" (TID:0xe792b8, sys_thread_t:0x7e1f20, Win32ID:0xfff5a0ef, state:CW) prio=4
                java.lang.Object.wait(Object.java:315)
                sun.awt.ScreenUpdater.nextEntry(ScreenUpdater.java:78)
                sun.awt.ScreenUpdater.run(ScreenUpdater.java:98)
            "TimerQueue" (TID:0xe6e498, sys_thread_t:0x7cec00, Win32ID:0xfff59ec3, state:CW) prio=4
                com.sun.java.swing.TimerQueue.run(TimerQueue.java:249)
                java.lang.Thread.run(Thread.java:474)
            "AWT-Windows" (TID:0xe664f0, sys_thread_t:0x7b5c00, Win32ID:0xfff580cb, state:R) prio=5
                sun.awt.windows.WToolkit.run(WToolkit.java:106)
                java.lang.Thread.run(Thread.java:474)
            "AWT-EventQueue-0" (TID:0xe66308, sys_thread_t:0x7b42d0, Win32ID:0xfff582f3, state:MW) prio=5
                java.awt.Component.invalidate(Component.java:1126)
                java.awt.Container.invalidate(Container.java:485)
                com.sun.java.swing.JComponent.revalidate(JComponent.java:2907)
                com.sun.java.swing.text.DefaultTextUI$RootView.preferenceChanged(DefaultTextUI.java:714)
                com.sun.java.swing.text.View.preferenceChanged(View.java:84)
                com.sun.java.swing.text.BoxView.preferenceChanged(BoxView.java:108)
                com.sun.java.swing.text.WrappedPlainView$WrappedLine.removeUpdate(Wrappe
                com.sun.java.swing.text.WrappedPlainView.removeUpdate(WrappedPlainView.java:345)
                com.sun.java.swing.text.DefaultTextUI$RootView.removeUpdate(DefaultTextUI.java:848)
                com.sun.java.swing.text.DefaultTextUI$UpdateHandler.removeUpdate(DefaultTextUI.java:1065)
                com.sun.java.swing.text.AbstractDocument.fireRemoveUpdate(AbstractDocument.java:185)
                com.sun.java.swing.text.AbstractDocument.remove(AbstractDocument.java:371)
                com.sun.java.swing.text.JTextComponent.setText(JTextComponent.java:1088)
                Test2.addToClause(Test2.java:139)
                Test2.functionPicked(Test2.java:107)
                Test2$FunctionListener_.mouseClicked(Test2.java:161)
                java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:216)
                java.awt.Component.processMouseEvent(Component.java:2287)
                java.awt.Component.processEvent(Component.java:2129)
                java.awt.Container.processEvent(Container.java:894)
            "Finalizer thread" (TID:0xe60088, sys_thread_t:0x7af380, Win32ID:0xfff4e1b3, state:CW) prio=2
            "main" (TID:0xe600b0, sys_thread_t:0x7ab720, Win32ID:0xfff127af, state:CW) prio=5
        Monitor Cache Dump:
            java.lang.Object@E63DF8/EACFB8: owner "AWT-Dispatch-Proxy" (0x7dac80, 6 entries)
            sun.awt.ScreenUpdater@E792B8/F01680: <unowned>
                Waiters: 1
            com.sun.java.swing.text.PlainDocument@E6F1E8/ED2020: <unowned>
                Waiters: 1
            com.sun.java.swing.TimerQueue@E6E4A0/ECEBC0: <unowned>
                Waiters: 1
        Registered Monitor Dump:
            Thread queue lock: <unowned>
                Waiters: 1
            Name and type hash table lock: <unowned>
            String intern lock: <unowned>
            JNI pinning lock: <unowned>
            JNI global reference lock: <unowned>
            BinClass lock: <unowned>
            Class loading lock: <unowned>
            Java stack lock: <unowned>
            Code rewrite lock: <unowned>
            Heap lock: <unowned>
            Has finalization queue lock: <unowned>
            Finalize me queue lock: <unowned>
                Waiters: 1
            Monitor registry: <unowned>
        ________________________________________________________________
        import java.awt.event.*;
        import java.awt.*;
        import java.util.*;
        import com.sun.java.swing.*;
        import com.sun.java.swing.event.*;
        import com.sun.java.swing.table.*;
        /**
        Try to recreate the hangs I see when dismissing dialogs.
        **/
        public class Test2 extends JPanel
        {
        static JFrame frame;
        JList functionList_;
        private JTextArea clause_;
        /**
        Ctor.
        **/
        public Test2 ()
        throws Exception
        {
            GridBagLayout layout = new GridBagLayout();
            setLayout(layout);
            GridBagConstraints constraints = new GridBagConstraints();
            // List box for functions
            // Label
            JLabel functionLabel = new JLabel("Functions");
            functionLabel.setName("selectFunctionLabel");
            constraints.insets = new Insets(5,10,5,10);
            constrain (functionLabel, this, layout, constraints,
                        0, 1, 100,
                        6, 1, 0,
                        GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
            // List box
            String [] functionChoices = {"AVG", "COUNT", "MIN", "MAX", "SUM"};
            functionList_ = new JList(functionChoices);
            functionList_.setName("selectFunctionList");
            JScrollPane functionListScroll = new JScrollPane(functionList_);
            constrain (functionListScroll, this, layout, constraints,
                        0, 1, 100,
                        7, 4, 0,
                        GridBagConstraints.VERTICAL, GridBagConstraints.WEST);
            // Listen for double clicks on list.
            functionList_.addMouseListener(new FunctionListener_());
            // Edit area for result.
            // Label
            JLabel clauseLabel = new JLabel("Result");
            clauseLabel.setName("selectClauseLabel");
            constraints.insets = new Insets(20,10,5,10);
            constrain (clauseLabel, this, layout, constraints,
                        0, 1, 100,
                        11, 1, 0,
                        GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
            // Text area
            clause_ = new JTextArea(10,60);
            clause_.setName("selectClause");
            clause_.setText("*");
            clause_.setLineWrap(true);
            JScrollPane clauseScroll = new JScrollPane(clause_);
            constraints.insets = new Insets(5,10,20,10);
            constrain (clauseScroll, this, layout, constraints,
                        0, 3, 100,
                        12, 3, 50,
                        GridBagConstraints.BOTH, GridBagConstraints.WEST);
        }
            public static void constrain (Component component,
                                          JPanel panel,
                                          GridBagLayout layout,
                                          GridBagConstraints constraints,
                                          int gridx, int gridwidth, int weightx,
                                          int gridy, int gridheight, int weighty,
                                          int fill, int anchor)
            {
                panel.add (component);
                constraints.gridx = gridx;
                constraints.gridy = gridy;
                constraints.gridwidth = gridwidth;
                constraints.gridheight = gridheight;
                constraints.fill = fill;
                constraints.anchor = anchor;
                constraints.weightx = weightx;
                constraints.weighty = weighty;
                layout.setConstraints (component, constraints);
            }
        /* private*/ void functionPicked(String item)
        {
            if (item.equals("COUNT"))
            {
                String result = JOptionPane.showInputDialog(this, // parent
                    "Type in value for COUNT.", // message
                    "Constant", // title
                    JOptionPane.QUESTION_MESSAGE); // message type
                // add to clause
                addToClause("COUNT(" + result + ")");
            }
            else
            // All other functions need a field name.
            {
                // Show dialog to have user choose field.
                String[] choices = new String[] {"one", "two", "three"};
                Object choice = JOptionPane.showInputDialog(this, // parent
                    "Value for function " + item + "()", // message
                    item, // title
                    JOptionPane.QUESTION_MESSAGE, // message type
                    null, // icon
                    choices, // choices
                    choices[0]); // initial choice
                if (choice != null) // null means they cancelled
                {
                    addToClause(item + "(" + choice + ")");
                }
            }
        }
        private void addToClause(String text)
        {
            if (clause_.getText().trim().equals("*") ||
                clause_.getText().trim().equals(""))
            {
                // first item added, replace asterisk with text
                clause_.setText(text);
            }
            else
            {
                // add text to clause with comma separator
                  clause_.setText(clause_.getText() + ", " + text);
            }
        }
        /**
        Class which listens for double-clicks on the function list
        **/
        private class FunctionListener_
        extends MouseAdapter
        {
            public void mouseClicked (MouseEvent event)
            {
                if (event.getClickCount () > 1) // if double click
                {
                    // Get the object that was double clicked, if any.
                    int row = functionList_.locationToIndex (event.getPoint ());
                    if (row != -1) // -1 means no object under mouse
                    {
                        Object object = functionList_.getModel().getElementAt(row);
                        if (object != null) // should never be null
                        {
                            functionPicked(object.toString());
                        }
                    }
                }
            }
        }
        /**
        MAIN
        **/
        public static void main(String args[])
            throws Exception
        {
            WindowListener l = new WindowAdapter()
            {
                public void windowClosing(WindowEvent e)
                {
                    System.exit(0);
                }
            };
        frame = new JFrame ("Test Visual");
            frame.addWindowListener(l);
            frame.getContentPane().setLayout(new BorderLayout());
            Test2 gui = new Test2();
            frame.getContentPane().add("Center", gui);
        frame.setSize(800, 600);
            frame.pack();
            frame.setVisible(true);
        }
        }
        Machine Details: 32MB Pentium 166
        Similar Problems have been raised in the comp.lang.java.gui newsgroup:
        _________________________________________
        ***** Thread # 1 ********
        _________________________________________
        Subject: Deadlock with Swing 1.0.1
                Date: Tue, 10 Mar 1998 07:54:01 -0600
               From: "Dave Hoag" <###@###.###>
         Organization: Netcom
         Newsgroups: comp.lang.java.gui
          I've discovered a potential deadlock with the latest version of swing.
        I'm running swing 1.0.1 with JDK1.1.5.
          The potential problem can occur when you use a JTextField. The real cause
        of the problem lies within com.sun.java.swing.text.AbstractDocument and the
        way it handles 'thread safe' access to a Document.
          When I issue a set text, this will take out a writeLock on a document.
        When another thread attempts to read the documents value it attempts to take
        out a readLock, if there is a currently writeLock, it 'wait()'s until it can
        safely read the value.
          Here is the deadlock scenario.
        On the core java Event thread I push a button that will eventually call a
        setText on the JTextField. This takes out a writeLock.
        On the core java Dispatch-Proxy thread, it starts to repaint my screen.
        When it reaches the JTextField, it waits.
        When processing the setText on the other thread it eventually fires an
        InsertUpdate event. Swing's code eventually calls Component.invalidate().
        Well, to do this it synchronizes on Component.lock. To bad, because it
        appears that the waiting Dispatch-Proxy thread has this lock. Deadlock
        occurs. The Dispatch-Proxy thread is waiting on read access to the
        JTextField and the Event thread is waiting on Component.lock.
        - Dave Hoag
        ObjectWave Corp.
        _________________________________________
        Subject: Re: Deadlock with Swing 1.0.1
                Date: Tue, 10 Mar 1998 23:03:58 -0500
               From: "Scott M Stark" <###@###.###>
         Organization: IBM.NET
         Newsgroups: comp.lang.java.gui
          References: 1
        Dave Hoag wrote in message <6e3gvl$###@###.###>...
        > I've discovered a potential deadlock with the latest version of swing.
        >I'm running swing 1.0.1 with JDK1.1.5.
        >
        > The potential problem can occur when you use a JTextField. The real cause
        >of the problem lies within com.sun.java.swing.text.AbstractDocument and the
        >way it handles 'thread safe' access to a Document.
        >
        Here is a simple example that deadlocks every time
        on a dual processor NTsp3 box using JDK1.1.5 using swing-1.0.1.
        --- Begin TstJFileChooser.java ---
        import com.sun.java.swing.BorderFactory;
        import com.sun.java.swing.JButton;
        import com.sun.java.swing.JFrame;
        import com.sun.java.swing.JPanel;
        import com.sun.java.swing.JTextField;
        import com.sun.java.swing.preview.JFileChooser;
        import java.awt.*;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.awt.event.WindowAdapter;
        import java.awt.event.WindowEvent;
        import java.awt.event.WindowListener;
        import java.io.File;
        import java.io.FileOutputStream;
        import java.io.IOException;
        class TstJFileChooser extends JFrame
        {
          private transient JTextField mainClassField;
          public static void main(String[] args)
          {
            TstJFileChooser tst = new TstJFileChooser();
            tst.setVisible(true);
          }
          public TstJFileChooser()
          {
            super("JFileChooser Test");
            setBackground(Color.lightGray);
            setBounds(100, 100, 300, 80);
            getContentPane().setLayout(new BorderLayout());
            JPanel mainClassPanel = new JPanel();
            mainClassPanel.setLayout(new BorderLayout());
        mainClassPanel.setBorder(BorderFactory.createTitledBorder("Application/Applet C
        lass"));
            mainClassField = new JTextField();
            mainClassField.setEditable(false);
            mainClassField.setToolTipText("Class whose dependencies define the
        jar contents");
            mainClassPanel.add(mainClassFi

              amfowler Anne Fowler (Inactive)
              miflemi Mick Fleming
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: