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
  • GUI script performance error


    JAG98

    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.

    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)

    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

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.