AnsweredAssumed Answered

UiThreadingViolationException

Question asked by vincent on Jul 9, 2010

I have got UiThreadingViolationException when I dev a plugin for spark:

 

btw,this plugin works on the computer I develop it.But throw below exception on another computer.

The JDKs are same,and I just copy the whole spark dist from develop machine to the other.

 

org.pushingpixels.substance.api.UiThreadingViolationException: Component creation must be done on Event Dispatch Thread
     at org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities.testComponentCreationThreadingViolation(SubstanceCoreUtilities.java:1921)
     at org.pushingpixels.substance.internal.ui.SubstancePanelUI.createUI(SubstancePanelUI.java:57)
     at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at sun.reflect.misc.Trampoline.invoke(Unknown Source)
     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
     at javax.swing.UIDefaults.getUI(Unknown Source)
     at javax.swing.UIManager.getUI(Unknown Source)
     at javax.swing.JPanel.updateUI(Unknown Source)
     at javax.swing.JPanel.<init>(Unknown Source)
     at javax.swing.JPanel.<init>(Unknown Source)
     at javax.swing.JPanel.<init>(Unknown Source)
     at org.jivesoftware.groupchat.ui.GroupList.<init>(GroupList.java:119)
     at org.jivesoftware.groupchat.plugin.GroupChatPlugin.initialize(GroupChatPlugin.java:19)
     at org.jivesoftware.spark.PluginManager$2.run(PluginManager.java:510)
     at java.awt.event.InvocationEvent.dispatch(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)

.

 

GroupChatPlugin.java

groupList=new GroupList();
ClassLoader cl = getClass().getClassLoader();
URL url = cl.getResource("images/group.gif");
ImageIcon icon = new ImageIcon(url);
final Workspace workspace = SparkManager.getWorkspace();
workspace.getWorkspacePane().addTab("Groups", icon, groupList);

 

GroupList.java

     public GroupList() {
        // Load Local Preferences
        setLayout(new BorderLayout());

         model = new DefaultListModel();
        groupItemList = new JList(model);
         groupItemList.setCellRenderer(new JPanelRenderer());
         groupItemList.addMouseListener(this);
         listPanel = new JPanel(new BorderLayout());
        listPanel.add(groupItemList,BorderLayout.CENTER);

         groupListScrollPane = new JScrollPane(listPanel);
        groupListScrollPane.setAutoscrolls(true);

        groupListScrollPane.setBorder(BorderFactory.createEmptyBorder());
        groupListScrollPane.getVerticalScrollBar().setBlockIncrement(50);
        groupListScrollPane.getVerticalScrollBar().setUnitIncrement(20);

        add(groupListScrollPane, BorderLayout.CENTER);

         workspace = SparkManager.getWorkspace();
         
        // Save state on shutdown.
        SparkManager.getMainWindow().addMainWindowListener(new MainWindowListener() {
            public void shutdown() {
                //saveState();
            }

            public void mainWindowActivated() {

            }

            public void mainWindowDeactivated() {

            }
        });

        SparkManager.getConnection().addConnectionListener(this);

         buildGroupList();
    }

Outcomes