2012-05-20 7 views
2

Java Helper Library의 진행 방법을 표시하는 방법으로 사용할 수있는 "창없는"스윙 구성 요소 (이미지)를 표시하는 방법을 쓰고 있습니다. 나는 전에 asked how to do this을 사용했고 내가 사용하고있는 좋은 대답을 받았다. the animated gif이 (가) 애니메이션으로 작동하지 않는 경우 효과가 있습니다. (나는 이미지를 사용하지 않습니다. 왜냐하면이 모든 것을 읽으면 아플 수 있습니다 ...) 움직이지 않는 것처럼 움직이지는 않습니다. 겉으로보기에는 일시 중지되었거나 뭔가 있습니다. 다른 질문에 대한 대답은 움직이는 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; 
} 
+2

해당 코드는 복사/붙여 넣기/** 컴파일되지 않습니다. ** ** SSCCE가 아닙니다 **. 이미지를 보려면 http://pscode.org/media/starzoom-thumb.gif 또는 (더 작은) http://1point1c.org/gif/thum/plnttm.gif –

+0

으로 핫 링크를 사용하십시오. 이벤트 디스패치 스레드의 구성 요소를 스윙하고 무언가가 변경되는지 확인합니다. –

+0

@AndrewThompson, 저는 정상적으로 SSCCE를 게시하는 것이 좋습니다. 나는 SSCCE에 관한 그 부분을 제거 할 것이다. 나는 그것을 포함시킬 것이지만 당신이 옳았다는 것을 발견했습니다. 그 방법이 문제입니다. URL에서 이미지를 가져온 후 효과가 좋습니다. 답변을 게시하려면 동의하겠습니다. 그것을 들여다 주셔서 감사합니다. – kentcdodds

답변

2
SwingHelper.resizeImageFromResourceBy(
    TestClass.class, progressImageLocation, 32, true); 
    //This just gets the image in the right size I want it. 

SSCCE의 내 추측의 짧은, 헬퍼 방법은 원본 이미지의 정적 (크기 조정) 버전을 반환한다는 것입니다이 잘못? 구현하고 .

레이블에 HTML을 사용하면 애니메이션 GIF 의 크기가 '즉석에서 조정'될 수 있지만 효과는 최적이 아닙니다. 이미지를 올바른 크기로 디자인하는 것이 좋습니다.

관련 문제