Search code examples
javasizesplash-screen

Size of splash screen IDE


For my thesis work, I need to create an IDE and I want to create a splash screen for the IDE. So my first question is that I don't know which size for the image I must create for the splash screen. My second question is that probably a lot of different screen resolutions are available in the market and the screen splash might be bigger or smaller for some computers... Is there anything that we could do to solve this ?

P.S.: I really liked the splash screen from IntelliJ IDE (15), I want to create something like that as a splash screen.

//----------------------------------------------------------------//

Solution for question 2:

    //Get the resolution of the screen PC
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    int X = (toolkit.getScreenSize().width);
    int Y = (toolkit.getScreenSize().height);

    //Get the  pixels of the screen middle resolution
    int cX = (toolkit.getScreenSize().width / 2) - ((int)((ImageView) s.lookup("#splash_logo")).getFitWidth())/2;
    int cY = (toolkit.getScreenSize().height / 2) - ((int)((ImageView) s.lookup("#splash_logo")).getFitHeight()/2);

    //Set the position of Stage to middle
    primaryStage.setX(cX);
    primaryStage.setY(cY);

Solution

  • If you want to scale it in relation to the monitor's resolution, I'd first get the height and width with the java.awt.Toolkit:

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    int X = (toolkit.getScreenSize().width)
    int Y = (toolkit.getScreenSize().height)
    

    Then you can scale an image that you're using for your splashscreen by using this method:

    public BufferedImage scaleImage(int multiplier, BufferedImage img) {
    
        BufferedImage bi = new BufferedImage(multiplier * img.getWidth(null), multiplier * img.getHeight(null), BufferedImage.TYPE_INT_RGB);
    
        Graphics2D grph = (Graphics2D) bi.getGraphics();
        grph.scale(multiplier, multiplier);
    
        // everything drawn with grph from now on will get scaled.
        grph.drawImage(img, 0, 0, null);
        grph.dispose();
    
        return bi;
    }
    

    Then center it on the screen by calculating the middle and setting your component there:

        int cX = (toolkit.getScreenSize().width / 2) - (getWidth() / 2);
        int cY = (toolkit.getScreenSize().height / 2) - (getHeight() / 2);
        component.setLocation(cX, cY);
    

    actual implementation is up to you, but these are the tools I use and it works fine for me. Hope this helps!