Skip to content

Troubleshooting

This script's GUI is causing performance issues.

If the client complains that your script's GUI is causing performance issues, you're either creating Swing components or invoking one of their methods from the wrong thread.

Swing is not thread safe, so you'll need to ensure all of your Swing related code is ran on the Event Dispatch Thread (EDT).

Danger

Make sure any code ran on the EDT is used only for Swing methods. Doing heavy processing on this thread will cause the whole client to freeze and cause other problems.

You can use SwingUtilities.invokeLater to run a block of code asynchronously, meaning you don't need the result right away (or ever). This is the preferred method for using Swing, as it's easier to reason about and it doesn't block your script's thread.

If for whatever reason you need immediate access to the result, you can use SwingUtilities.invokeAndWait to block and wait until that code is ran.

Example:

SwingUtilities.invokeLater(() -> {
    MyGUI gui = new MyGUI()
    gui.setVisible(true):
});