JAVA 6 スプラッシュ画面の表示に問題があるため、次の方法を使用してスプラッシュ ウィンドウを表示しました。
File splashImageFile = new File(Constants.PATH_IMAGE + "splash.png");
final BufferedImage img = ImageIO.read(splashImageFile);
final JWindow window = new JWindow() {
private static final long serialVersionUID = -132452345234523523L;
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Rectangle windowRect = getBounds();
try {
Robot robot = new Robot(getGraphicsConfiguration().getDevice());
BufferedImage capture = robot.createScreenCapture(new Rectangle(windowRect.x, windowRect.y, windowRect.width, windowRect.height));
g2.drawImage(capture, null, 0, 0);
} catch (IllegalArgumentException iae) {
System.out.println("Argumets mis matched.\n" + iae.getMessage());
} catch(SecurityException se){
System.out.println("Security permission not supported\n" + se.getMessage());
} catch (AWTException ex) {
System.out.println("Exception found when creating robot.\n" + ex.getMessage());
}
g2.drawImage(img, 0, 0, null);
g2.setFont(new Font("TimesRoman", Font.BOLD, 15));
g2.drawString("Loading...", 320, 260);
g2.dispose();
}
};
window.setAlwaysOnTop(true);
window.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
window.repaint();
ウィンドウに角の丸い長方形が必要なため、画像はpng透明画像です。Win 7 で動作しますが、Mac 10.8 で動作します。Mac ではまだ長方形の背景が表示されます。実際には背景としても見えません。誰かがその原因を教えてもらえますか。以下は、各プラットフォームのイメージです。
Windows 上
マック上
前もって感謝します。
編集:
回答は素晴らしいですが、AWTUtilities が常にシステム サポートを受けているとは限らないことがわかりました。そのため、一部のシステムでは、回答済みのメソッドが失敗する場合があります。正式な解決策はありませんか?解決策は基本レベルから来るということですか?