Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8460155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:31:39+00:00 2026-06-10T13:31:39+00:00

I want to handle some exceptions using JOptionPane s. This is the main method:

  • 0

I want to handle some exceptions using JOptionPanes. This is the main method:

public class MainRun {

public static void main(String args[]){    
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                UIManager.setLookAndFeel(new SubstanceRavenGraphiteGlassLookAndFeel());
            }catch (Exception e){
                e.printStackTrace();
            }                 
            new MainGui().setVisible(true);                
            new Initialized().start();
            new PriorityMessageQueue().start();
        }
    });

MainGui is the main window (JFrame) of the application.
I handled exception inside the PriorityMessageQueue thread.

public class PriorityMessageQueue extends Thread {

@Override
public void run() {

    while (true) {
        try {
            instantMessages = instant.getMobitelMessagesToBeSent();
        } catch (Exception ex) {
                        JOptionPane.showMessageDialog(
                        null,
                        ex.getMessage(),
                        "Database Error",
                        JOptionPane.ERROR_MESSAGE);

        }

        ...

after I run this, I’m getting an error

   org.jvnet.substance.api.UiThreadingViolationException: Component creation must be done on Event Dispatch Thread
at org.jvnet.substance.utils.SubstanceCoreUtilities.testComponentCreationThreadingViolation(SubstanceCoreUtilities.java:2312)
at org.jvnet.substance.SubstanceOptionPaneUI.createUI(SubstanceOptionPaneUI.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:37)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:244)
at javax.swing.UIDefaults.getUI(UIDefaults.java:752)
at javax.swing.UIManager.getUI(UIManager.java:989)
at javax.swing.JOptionPane.updateUI(JOptionPane.java:1859)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1822)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1785)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1753)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1731)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1711)
at GUI.MainGui.showOptionPane(MainGui.java:1039)
at SMS.PriorityMessageQueue.run(PriorityMessageQueue.java:86)
    UIDefaults.getUI() failed: createUI() failed for
      javax.swing.JOptionPane
   [,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,p
   referredSize=,icon=,initialValue=,message=DatabaseConnection class
   connect,messageType=ERROR_MESSAGE,optionType=DEFAULT_OPTION,wantsInput=false]
   java.lang.reflect.InvocationTargetException
   java.lang.Error
at javax.swing.UIDefaults.getUIError(UIDefaults.java:712)
at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:133)
at javax.swing.UIDefaults.getUI(UIDefaults.java:758)
at javax.swing.UIManager.getUI(UIManager.java:989)
at javax.swing.JOptionPane.updateUI(JOptionPane.java:1859)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1822)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1785)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1753)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1731)
at javax.swing.JOptionPane.<init>(JOptionPane.java:1711)
at GUI.MainGui.showOptionPane(MainGui.java:1039)
at SMS.PriorityMessageQueue.run(PriorityMessageQueue.java:86)

And the JOptionPane will not display properly!

enter image description here

Instead of passing null to JOptionPane, how can I get the parentComponent (MainGui JFrame)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:31:40+00:00Added an answer on June 10, 2026 at 1:31 pm

    A JOptionPane is a mini Swing GUI, and like all Swing GUIs, it must be created on the Swing event thread, not on a background thread. This can be done by creating your JOptionPane in a Runnable and then queuing the Runnable on the event thread:

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        JOptionPane.showMessageDialog(....);
      }
    });
    

    For example,

    } catch (Exception ex) {
       final String exMessage = ex.getMessage();
    
       SwingUtilities.invokeLater(new Runnable() {
         public void run() {
           JOptionPane.showMessageDialog(
             null,
             exMessage,
             "Database Error",
             JOptionPane.ERROR_MESSAGE);
           );
         }
       });
      }
    }
    

    As for your question,

    Instead of passing null to JOptionPane, how can I get the parentComponent (MainGui JFrame)?

    You’ll need a reference to the main GUI. How you get this will depend on how your program is organized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem. Namely: I'm using spring aop to handle exceptions. Some of
I want to use WCF pipeline to handle requests of some custom format (not
I am using gcc on linux to compile C++ code. There are some exceptions
I am creating a data access layer where I want to handle exceptions that
I am using protobuf now for some weeks, but I still keep getting exceptions
Here is what I did, I want to gracefully handle this exception: code_snippet: my.cpp
After reading some threads on misuses of exceptions (basically saying you don't want to
I want to do some exception handling. I plan on using the __LINE__ and
Unchecked exceptions are alright if you want to handle every failure the same way,
In .NET, method signatures don't tell me if I have missed handling some exceptions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.