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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:44:22+00:00 2026-06-03T17:44:22+00:00

1.The window is flashing while repainting. How can I eliminate that? Using the update

  • 0

1.The window is flashing while repainting. How can I eliminate that? Using the update method doesn’t work either.
2. How do I update all the not-up-to-date classes in netbeans? It looks like my netbeans uses some old classes (before jdk 7).

import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JWindow;


public class Splash extends JWindow {

    private boolean mIsRunning;
    private boolean mIsFadingOut;
    volatile static boolean s = true;
    private int mAngle;
    private int mFadeCount;
    private int mFadeLimit = 15;

    Splash(Frame f) {
        super(f);
    }

    public void startt() {
        while (s) {
            repaint();

            mAngle += 3;
            if (mAngle >= 360) {
                mAngle = 0;
            }
            if (mIsFadingOut) {
                if (--mFadeCount == 0) {
                    mIsRunning = false;
                }
            } else if (mFadeCount < mFadeLimit) {
                mFadeCount++;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void paint(Graphics g) {
        int w = getWidth();
        int h = getHeight();

        // Paint the view.
        super.paintComponents(g);
        Graphics2D g2 = (Graphics2D) g.create();
        float fade = (float) mFadeCount / (float) mFadeLimit;
        // Gray it out.
        Composite urComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, .5f * fade));
        g2.fillRect(0, 0, w, h);
        g2.setComposite(urComposite);

        // Paint the wait indicator.
        int s = Math.min(w, h) / 5;
        int cx = w / 2;
        int cy = h / 2;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setStroke(
                new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g2.setPaint(Color.white);
        g2.rotate(Math.PI * mAngle / 180, cx, cy);
        for (int i = 0; i < 12; i++) {
            float scale = (11.0f - (float) i) / 11.0f;
            g2.drawLine(cx + s, cy, cx + s * 2, cy);
            g2.rotate(-Math.PI / 6, cx, cy);
            g2.setComposite(AlphaComposite.getInstance(
                    AlphaComposite.SRC_OVER, scale * fade));
        }

        g2.dispose();
    }
}

public void showSplash(){
    final JFrame p = this; //parent
    final  Rectangle s = this.getBounds(); //parent size

    new Thread(){
         public void run(){
             splash = new Splash(p);
             splash.setBounds(s);
             splash.setVisible(true);
             splash.startt();
         }
    }.start();
}

}

  • 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-03T17:44:28+00:00Added an answer on June 3, 2026 at 5:44 pm

    The problem comes from the fact that you override the paint method of JWindow. Override the paintComponent() of a JPanel instead, it has double buffering:

    import java.awt.AlphaComposite;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Composite;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JWindow;
    import javax.swing.SwingUtilities;
    
    public class Test extends JFrame {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    JWindow window = new JWindow();
                    final Splash splash = new Splash();
                    window.add(splash);
                    window.setSize(100, 30);
                    window.setVisible(true);
    
                    new Thread() {
    
                        @Override
                        public void run() {
                            splash.startt();
                        }
                    }.start();
                }
            });
        }
    
        public static class Splash extends JPanel {
    
            private boolean mIsRunning;
            private boolean mIsFadingOut;
            volatile static boolean s = true;
            private int mAngle;
            private int mFadeCount;
            private int mFadeLimit = 30;
    
            Splash() {
            }
    
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                int w = getWidth();
                int h = getHeight();
    
                // Paint the view.
                super.paintComponents(g);
                Graphics2D g2 = (Graphics2D) g.create();
                float fade = (float) mFadeCount / (float) mFadeLimit;
                // Gray it out.
                Composite urComposite = g2.getComposite();
                g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade));
                g2.fillRect(0, 0, w, h);
                g2.setComposite(urComposite);
    
                // Paint the wait indicator.
                int s = Math.min(w, h) / 5;
                int cx = w / 2;
                int cy = h / 2;
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                g2.setPaint(Color.white);
                g2.rotate(Math.PI * mAngle / 180, cx, cy);
                for (int i = 0; i < 12; i++) {
                    float scale = (11.0f - i) / 11.0f;
                    g2.drawLine(cx + s, cy, cx + s * 2, cy);
                    g2.rotate(-Math.PI / 6, cx, cy);
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade));
                }
    
                g2.dispose();
            }
    
            public void startt() {
                while (s) {
    
                    mAngle += 3;
                    if (mAngle >= 360) {
                        mAngle = 0;
                    }
                    if (mIsFadingOut) {
                        if (--mFadeCount == 0) {
                            mIsRunning = false;
                        }
                    } else if (mFadeCount < mFadeLimit) {
                        mFadeCount++;
                    }
                    repaint();
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

window.addEventListener(onbeforeunload,function() {return are you sure?}); ^ This does not seem to work... at all...
window.location.href does not work to save the current web page url as a bookmark.
$(window).bind(beforeunload,function(){ return cant be seen in ff; }); The problem is that i can't
How can i change the flashing input marker (the one that looks like this:
window.setInterval(function(){ $('#Notify-Bar').html('a new notification'); }, 5000); Did not work on IE, however works fine
Dialog window is not launched when pressing the link, can you see anything wrong
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS) doesn't work for me, since it should be called before onCreate in the
Window.open javascript function is not working in Mozilla, but working in other browsers, here
In almost all messengers when your IM window is minimized to the taskbar, IM
I have a WPF window that goes fullscreen, and I have made every attempt

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.