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

  • Home
  • SEARCH
  • 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 7904733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:12:29+00:00 2026-06-03T10:12:29+00:00

I’m making a splash screen for my application. It’s just static BufferedImage drawn by

  • 0

I’m making a splash screen for my application. It’s just static BufferedImage drawn by Graphics2D, inside JFrame with no decorations. My problem is: the window sometimes isn’t drawn properly, it means it doesn’t always contain my image, it’s sometimes just grey. I tried already creating splash screen in second thread, but it didn’t help. I could call splashScreen.repaint() every line, but it’s nonsense… Here’s my code:

package SeriousSteve.MapEditor;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;

/**
 * Simple splash screen, contains only the image.
 * 
 * @author m4tx3
 */
public class SplashScreen extends JFrame {

    private BufferedImage image;

    /**
     * Constructor. Creates a window with splash screen, loads an image at the
     * URL specified in imageURL, and finally displays this image.
     * 
     * @param imageURL  URL to the image that you want to put on the splash
     *                  screen.
     */
    public SplashScreen() {
        super("Splash screen");
    }

    public void createSplashScreen(final URL imageURL) {
        try {
            image = ImageIO.read(imageURL);
        } catch (IOException ex) {
            Logger.getLogger(SplashScreen.class.getName()).
                    log(Level.SEVERE, null, ex);
        }
        setUndecorated(true);
        setSize(image.getWidth(), image.getHeight());
        setLocationRelativeTo(null);
        setVisible(true);

        createGraphics();

        repaint();
    }

    /**
     * Creates a graphics context and draws a splash screen.
     */
    private void createGraphics() {
        Graphics2D g = (Graphics2D) getGraphics();
        g.drawImage(image, 0, 0, null);
    }

    /**
     * Closes the splash screen and frees the memory taken by the image.
     * 
     * Call this function when the loading is complete.
     */
    public void close() {
        setVisible(false);
        image = null;
        dispose();
    }
}

And:

    SplashScreen splashScreen = new SplashScreen();
    splashScreen.createSplashScreen(getClass().getResource(
            "Img/splash.png"));

Btw., – I’m creating my own splash screen class, because I’ve got 2 apps (the game and map editor for it) in 1 jar… I want to show splash screen only in map editor, so I can’t modify manifest file.

Regards

  • 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-03T10:12:34+00:00Added an answer on June 3, 2026 at 10:12 am

    Use a JLabel instead. Painting on the frame directly is a bad idea.

    See this, it works everytime:

    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.SwingUtilities;
    
    /**
     * Simple splash screen, contains only the image.
     * 
     * @author m4tx3
     */
    public class SplashScreen extends JFrame {
    
        /**
         * Constructor. Creates a window with splash screen, loads an image at the URL specified in imageURL, and finally displays this image.
         * 
         * @param imageURL
         *            URL to the image that you want to put on the splash screen.
         */
        public SplashScreen() {
            super("Splash screen");
        }
    
        public void createSplashScreen(final URL imageURL) {
    
            JLabel splashLabel = new JLabel(new ImageIcon(imageURL));
            add(splashLabel);
                setSize(splashLabel.getPreferredSize());
            setUndecorated(true);
            setLocationRelativeTo(null);
            setVisible(true);
    
            repaint();
        }
    
        /**
         * Closes the splash screen and frees the memory taken by the image.
         * 
         * Call this function when the loading is complete.
         */
        public void close() {
            setVisible(false);
            dispose();
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    try {
                        new SplashScreen().createSplashScreen(new URL(
                                "http://art.gnome.org/download/themes/splash_screens/1334/Splash-GnomeDarkSplashScreen.png"));
                    } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I am currently running into a problem where an element is coming back from
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.