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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:12:27+00:00 2026-05-17T22:12:27+00:00

I work on a UI java application composed from: top header left menu header

  • 0

I work on a UI java application composed from:

  • top header
  • left menu
  • header text
  • error message (displayed on the page’s header)
  • center container (JPanel) which is changed dinamically, in dependence of selected menu item (from left side)

When there are any computation errors, an error message is displayed on the application’s header (location in the page’s header).Error messages can be different, ones are composed from one row, but others are longer (2,3 rows)

When a long error appears, it may be displayed correctly or not (the message is displayed over other components).
As far as I know, on changing UI components the doLayout(), repaint() methods are invoked indepenendly and these should correct the layout.

Recently I read about EDT and noticed that a swing application should be organised according to EDT principles.

I think that this will solve my problem, because all the operations will be synchronized and I’ll manage the method calls’ consecutivity.

But now, I don’t have enough time to refactor the application and this is scheduled for next release.

Do you know another solution which will help in adjusting layouts? This problem is very tricky, I’m not able to reproduce it. But it appears from time to time.

Thanks a lot.
Sergiu

PS: If you have any questions or more details are needed, please don’t hesitate to contact me.

  • 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-17T22:12:28+00:00Added an answer on May 17, 2026 at 10:12 pm

    The following class checks for EDT violations. Install it before doing any other GUI related code as follows:

    RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
    

    Here’s the class:

    import javax.swing.JComponent;
    import javax.swing.RepaintManager;
    import javax.swing.SwingUtilities;
    
    public class CheckThreadViolationRepaintManager extends RepaintManager {
        private boolean completeCheck = true;
    
        public synchronized void addInvalidComponent(JComponent component) {
            checkThreadViolations(component);
            super.addInvalidComponent(component);
        }
    
        public boolean isCompleteCheck() {
            return completeCheck;
        }
    
        public void setCompleteCheck(boolean completeCheck) {
            this.completeCheck = completeCheck;
        }
    
        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())) {
                Exception exception = new Exception("EDT Violation");
                boolean repaint = false;
                boolean fromSwing = false;
                StackTraceElement[] stackTrace = exception.getStackTrace();
                for (StackTraceElement st : stackTrace) {
                    if (repaint && st.getClassName().startsWith("javax.swing.")) {
                        fromSwing = true;
                    }
                    if ("repaint".equals(st.getMethodName())) {
                        repaint = true;
                    }
                }
                if (repaint && !fromSwing) {
                    //no problems here, since repaint() is thread safe
                    return;
                }
                exception.printStackTrace();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the proper way for a Java command line application to do background work
I work in java web application . In some section i use very huge
I currently work on a Java web application that has relies on a permissions
I want to create a hidden folder using java application. That program should work
I have an Java application for copying large amounts of data from users' workstations
I want to create a small java application to copy some wiki content from
i need to read an external XML file from my java application in jar
I'm used to work with Java where large amounts of examples are available. For
How does the event creation and handling work in Java Swing?
Which of the WCF Service Protocols work well with Java? Do the TCP Service

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.