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 6704191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:15:37+00:00 2026-05-26T07:15:37+00:00

In connection with my question ( may be ), I found another exception type

  • 0

In connection with my question (may be), I found another exception type that I not able to catch and print-out from SwingWorker thread.

How can I to generate RepaintManager exceptions?

I read this CheckThreadViolationRepaintManager and this approach by Alexander Potochkin, but nothing seems to solve my issues.

  • 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-05-26T07:15:37+00:00Added an answer on May 26, 2026 at 7:15 am

    If it helps, the example below throws prints multiple variations of the following Exception, mostly for each phase of the frame’s UI delegate initialization. I used CheckThreadViolationRepaintManager, but the AspectJ variation looks interesting, too.

    java.lang.Exception
        at EDTViolation$CheckThreadViolationRepaintManager.checkThreadViolations(EDTViolation.java:43)
        at EDTViolation$CheckThreadViolationRepaintManager.addDirtyRegion(EDTViolation.java:37)
        at javax.swing.JComponent.repaint(JComponent.java:4734)
        at java.awt.Component.repaint(Component.java:3168)
        at javax.swing.JComponent.setFont(JComponent.java:2727)
        at javax.swing.LookAndFeel.installColorsAndFont(LookAndFeel.java:191)
        at javax.swing.plaf.basic.BasicPanelUI.installDefaults(BasicPanelUI.java:49)
        at javax.swing.plaf.basic.BasicPanelUI.installUI(BasicPanelUI.java:39)
        at javax.swing.JComponent.setUI(JComponent.java:662)
        at javax.swing.JPanel.setUI(JPanel.java:136)
        at javax.swing.JPanel.updateUI(JPanel.java:109)
        at javax.swing.JPanel.(JPanel.java:69)
        at javax.swing.JPanel.(JPanel.java:92)
        at javax.swing.JPanel.(JPanel.java:100)
        at javax.swing.JRootPane.createGlassPane(JRootPane.java:528)
        at javax.swing.JRootPane.(JRootPane.java:348)
        at javax.swing.JFrame.createRootPane(JFrame.java:255)
        at javax.swing.JFrame.frameInit(JFrame.java:236)
        at javax.swing.JFrame.(JFrame.java:159)
        at EDTViolation.main(EDTViolation.java:12)
    ...
    
    import java.lang.ref.WeakReference;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.RepaintManager;
    import javax.swing.SwingUtilities;
    
    /** @see https://stackoverflow.com/questions/7787998 */
    public class EDTViolation {
    
        public static void main(String args[]) {
            RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setVisible(true);
        }
        
        private static class CheckThreadViolationRepaintManager extends RepaintManager {
        //http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html
    
            private boolean completeCheck = true;
            private WeakReference<JComponent> lastComponent;
    
            public CheckThreadViolationRepaintManager(boolean completeCheck) {
                this.completeCheck = completeCheck;
            }
    
            public CheckThreadViolationRepaintManager() {
                this(true);
            }
    
            public boolean isCompleteCheck() {
                return completeCheck;
            }
    
            public void setCompleteCheck(boolean completeCheck) {
                this.completeCheck = completeCheck;
            }
    
            @Override
            public synchronized void addInvalidComponent(JComponent component) {
                checkThreadViolations(component);
                super.addInvalidComponent(component);
            }
    
            @Override
            public void addDirtyRegion(JComponent component, int x, int y, int w, int h) {
                checkThreadViolations(component);
                super.addDirtyRegion(component, x, y, w, h);
            }
    
            private void checkThreadViolations(JComponent c) {
                if (!SwingUtilities.isEventDispatchThread() && (completeCheck || c.isShowing())) {
                    boolean repaint = false;
                    boolean fromSwing = false;
                    boolean imageUpdate = false;
                    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
                    for (StackTraceElement st : stackTrace) {
                        if (repaint && st.getClassName().startsWith("javax.swing.")
                            && // for details see 
                            // https://swinghelper.dev.java.net/issues/show_bug.cgi?id=1
                            !st.getClassName().startsWith("javax.swing.SwingWorker")) {
                            fromSwing = true;
                        }
                        if (repaint && "imageUpdate".equals(st.getMethodName())) {
                            imageUpdate = true;
                        }
                        if ("repaint".equals(st.getMethodName())) {
                            repaint = true;
                            fromSwing = false;
                        }
                        if ("read".equals(st.getMethodName()) && "javax.swing.JEditorPane".equals(st.getClassName())) {
                            // Swing reads html from a background thread
                            return;
                        }
                    }
                    if (imageUpdate) {
                    //assuming it is java.awt.image.ImageObserver.imageUpdate(...) 
                        //image was asynchronously updated, that's ok 
                        return;
                    }
                    if (repaint && !fromSwing) {
                        //no problems here, since repaint() is thread safe
                        return;
                    }
                    //ignore the last processed component
                    if (lastComponent != null && c == lastComponent.get()) {
                        return;
                    }
                    lastComponent = new WeakReference<JComponent>(c);
                    violationFound(c, stackTrace);
                }
            }
    
            protected void violationFound(JComponent c, StackTraceElement[] stackTrace) {
                System.out.println();
                System.out.println("EDT violation detected");
                System.out.println(c);
                for (StackTraceElement st : stackTrace) {
                    System.out.println("\tat " + st);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is a different question concerning: add a connection to database not working, asp.net
Edit: After addressing some issues that may or may not have been causing problems,
I have found out (in a hard way) that a collection that is being
Connection.close() may throw SqlException , but I have always assumed that it is safe
This may be a basic C# question, but I'm comming from a C/C++ background.
This may be a question that has been answered before - if so please
This may be a very old, many times asked question. But I am not
Short summary: How to accept content that may be endless and not uploaded at
This may be a question about convention, best practices and/or personal preferences: So I'm
The question is if a database connection should be passed in by reference or

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.