3 Replies Latest reply: Mar 27, 2013 5:17 AM by Kayaman RSS

    java.lang.IllegalStateException For AutoCompleteSupport GlazedLists

    999304
      Hi,
      I am getting following exception :
      java.lang.IllegalStateException: AutoCompleteSupport must be accessed from the Swing Event Dispatch Thread, but was called on Thread "main"

      I have written following code in constructor of my class BillScreen_1 which extends JDialog

      AutoCompleteSupport support =AutoCompleteSupport.install(this.prodComboBox_1, GlazedLists.eventList(prod_List));

      And my main method is simply like:
      public static void main(String[] args) {
                try {
                     BillScreen_1 dialog = new BillScreen_1();
                     dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                     dialog.pack();
                     dialog.setVisible(true);
                } catch (Exception e) {
                     e.printStackTrace();
                }
           }

      Can somebody pls help me regarding this exception
        • 1. Re: java.lang.IllegalStateException For AutoCompleteSupport GlazedLists
          rp0428
          And do you see anywhere in there where you are creating a thread other than the 'main' thread?

          See the Java Tutorials
          http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html
          >
          The Event Dispatch Thread
          Swing event handling code runs on a special thread known as the event dispatch thread. Most code that invokes Swing methods also runs on this thread. This is necessary because most Swing object methods are not "thread safe": invoking them from multiple threads risks thread interference or memory consistency errors. Some Swing component methods are labelled "thread safe" in the API specification; these can be safely invoked from any thread. All other Swing component methods must be invoked from the event dispatch thread. Programs that ignore this rule may function correctly most of the time, but are subject to unpredictable errors that are difficult to reproduce.


          --------------------------------------------------------------------------------
          A note on thread safety: It may seem strange that such an important part of the Java platform is not thread safe. It turns out that any attempt to create a thread-safe GUI library faces some fundamental problems. For more on this issue, see the following entry in Graham Hamilton's blog: MultiThreaded toolkits: A failed dream?
          --------------------------------------------------------------------------------

          It's useful to think of the code running on the event dispatch thread as a series of short tasks. Most tasks are invocations of event-handling methods, such as ActionListener.actionPerformed. Other tasks can be scheduled by application code, using invokeLater or invokeAndWait. Tasks on the event dispatch thread must finish quickly; if they don't, unhandled events back up and the user interface becomes unresponsive.

          If you need to determine whether your code is running on the event dispatch thread, invoke javax.swing.SwingUtilities.isEventDispatchThread.
          • 2. Re: java.lang.IllegalStateException For AutoCompleteSupport GlazedLists
            999304
            no i don't have any other thread than main
            • 3. Re: java.lang.IllegalStateException For AutoCompleteSupport GlazedLists
              Kayaman
              996301 wrote:
              no i don't have any other thread than main
              Yes you do. The Swing Event Dispatch Thread. See SwingUtilities.invokeAndWait() and invokeLater() methods (and google) for more information.