Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • GUI script performance error


    JAG98
     Share

    Recommended Posts

    Wrote the first ever script for a gui. A simple small snippet with one ComboBox, a start button and a label. It selects from the user what is to be looted. Got a big pile of error. Here is what was copied to the clipboard.
     

    Spoiler

    7:02:34 pm: [ERROR] Swing threading error::
        org.pushingpixels.substance.api.UiThreadingViolationException: Swing component creation must be done on the Event Dispatch Thread. Try wrapping your method in SwingUtilities#invokeLater.
        at org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities.testComponentCreationThreadingViolation(SubstanceCoreUtilities.java)
        at org.pushingpixels.substance.internal.ui.SubstanceLabelUI.createUI(SubstanceLabelUI.java)
        at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
        at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at java.base/sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:260)
        at java.desktop/javax.swing.UIDefaults.getUI(UIDefaults.java:806)
        at java.desktop/javax.swing.UIManager.getUI(UIManager.java:1064)
        at java.desktop/javax.swing.JLabel.updateUI(JLabel.java:270)
        at java.desktop/javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1363)
        at java.desktop/javax.swing.SwingUtilities.updateComponentTreeUI(SwingUtilities.java:1354)
        at java.desktop/javax.swing.JComboBox.updateUI(JComboBox.java:281)
        at java.desktop/javax.swing.JComboBox.init(JComboBox.java:236)
        at java.desktop/javax.swing.JComboBox.<init>(JComboBox.java:230)
        at GUISource.initComponents(GUISource.java:19)
        at GUISource.<init>(GUISource.java:9)
        at CombatTrainer.onStart(CombatTrainer.java:45)
        at org.dreambot.api.script.AbstractScript.run(AbstractScript.java)
        at java.base/java.lang.Thread.run(Thread.java:832)
     

    So, what can be done? Don't really know much about Swing and mostly based this script off of a YT guide.
    ETA: After that error, the script works just fine.

    Edited by JAG98
    Link to comment
    Share on other sites

    The error is saying you need to wrap the code which creates the GUI in a lambda put into SwingUtilities.invokeLater(..).

    SwingUtilities.invokeLater(() => createGUI()); 

    Imagine createGUI() is entrypoint function which creates the JPanels and stuff. You can put this in the onStart() of your script.

    (reference: https://dreambot.org/forums/index.php?/topic/8530-scripting-101/ see first note in the GUI section)

    Edited by flipjazz
    Link to comment
    Share on other sites

    On 3/24/2021 at 7:52 PM, flipjazz said:

    The error is saying you need to wrap the code which creates the GUI in a lambda put into SwingUtilities.invokeLater(..).

    SwingUtilities.invokeLater(() => createGUI()); 

    Imagine createGUI() is entrypoint function which creates the JPanels and stuff. You can put this in the onStart() of your script.

    (reference: https://dreambot.org/forums/index.php?/topic/8530-scripting-101/ see first note in the GUI section)

     

    On 3/24/2021 at 7:21 PM, Neffarion said:

    Yeah wrapped up the createGUI() in SwingUtilities.invokeLater(). Worked like a charm. Thanks you two!

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.