0

I just switched to java 9 from java 8. I am using following code to build a splash screen. Splash screen comes in the center of the monitor if I use java 8, but with java 9 its not in center. Any idea, what can I do?

public void showSplashScreen() throws MalformedURLException
{
    dialog = new JDialog();
    dialog.setModal(false);
    dialog.setUndecorated(true);
    dialog.getRootPane().setOpaque(false);
    dialog.getContentPane().setBackground(new Color(0, 0, 0, 0));
    dialog.setBackground(new Color(0, 0, 0, 0));

    URL imageURL = SomeClass.class.getClassLoader().getResource("resources/" + fImage);
    JLabel background = new JLabel(new ImageIcon(imageURL));
    background.setLayout(new BorderLayout());
    dialog.add(background);
    String versionInfo = readVersion();
    JLabel text = new JLabel(versionInfo);
    text.setFont(new Font("Courier New", Font.PLAIN, 14));
    text.setForeground(Color.WHITE);

    text.setBorder(BorderFactory.createEmptyBorder(240, 272, 150, 50));
    background.add(text);

    progressBar.setMaximum(PROGBAR_MAX);
    dialog.add(progressBar, BorderLayout.SOUTH);
    startProgressBar();

    dialog.pack();
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);
}

Example

user1631306
  • 4,350
  • 8
  • 39
  • 74
  • Why don’t you use the [builtin splash screen](https://docs.oracle.com/javase/8/docs/api/?java/awt/SplashScreen.html) feature? It has the advantage of being shown much earlier during startup. – Holger Mar 08 '18 at 08:09
  • My current code is working fine with the ability of putting dynamic text at certain location on the screen. – user1631306 Mar 08 '18 at 17:43
  • The builtin splash screen also allows drawing on it. – Holger Mar 09 '18 at 07:58
  • I figured, dialog.setUndecorated(true); dialog.setBackground(new Color(0, 0, 0, 0)); are causing the issue. Dont know why, but having them in my code cause the issue. But I need them to make the transparent background. – user1631306 Mar 16 '18 at 17:34

0 Answers0