進行状況ホイールなどを表示する方法として使用できる「ウィンドウのない」スイングコンポーネント(画像)を表示するJavaヘルパーライブラリのメソッドを作成しています。少し前にこれを行う方法を尋ねたところ、私が使用している良い答えを受け取りました。アニメーションGIFがアニメーション化されていないことを除いて、うまく機能します。(画像自体は使用していません。これを読んでいる間ずっと画像を見ると気分が悪くなる可能性があるためです...)動かないのでアニメーション化されていません。一見一時停止か何かです。他の質問に対する答えは、アニメーションGIFがうまく機能すると述べました。答えは間違っていますか、それとも私はこれを間違って実装していますか?:
public static void main(String[] args) throws IOException, InterruptedException {
Image image = SwingHelper.resizeImageFromResourceBy(TestClass.class, progressImageLocation, 32, true); //This just gets the image in the right size I want it.
JWindow window = SwingHelper.getProgressWheelWindow(new ImageIcon(image), .9f, 600, 400);
window.setVisible(true);
Thread.sleep(3000); //Just so the image only shows up for a short period of time.
window.setVisible(false);
SwingHelper.centerAndPack(window); //A method to center and pack the window
}
/**
* Returns a window with a partially opaque progress Icon
*
* @param icon the icon to set in the progress window
* @param opacity a float value from 0-1
* @param x the x location of the window
* @param y the y location of the window
* @return a jWindow of the progress wheel
*/
public static JWindow getProgressWheelWindow(final Icon icon, final Float opacity, final int x, final int y) {
JWindow jWindow = new JWindow() {
{
setOpacity(opacity);
setLocation(x, y);
setSize(icon.getIconWidth(), icon.getIconHeight());
add(new JLabel(icon));
pack();
}
};
return jWindow;
}