2016-06-13 1 views
0

세 개의 JPanel, fatherPanel, childPanel1, childrenPanel2가 있습니다.페인트 도구와 SwingUtilities.updateComponentTreeUI의 차이점은 무엇입니까?

버튼을 클릭하면 아버지 패널에서 현재 자식 패널을 제거하고 아버지 패널에 다른 자식을 추가합니다.

매번 revalidate() 및 repaint()를 호출하여 UI를 업데이트해야합니다.

그런 다음 SwingUtilities.updateComponentTreeUI()에 동일한 효과가 있음을 알고 있습니다.

나는 두 개의 차이점이 있는지 알고 싶습니까?

답변

2

스윙은 플러그 가능 Look-n-Feel을 지원합니다. 런타임시 L & F를 변경할 때 updateComponentTreeUI 메서드를 사용하여이 변경 사항에 대해 모든 구성 요소에 알릴 필요가 있습니다. 새로운 L & F로 인해 구성 요소 크기가 변경 될 수 있으므로 스윙은 revalidate를 호출하여 레이아웃을 다시 계산해야합니다. 여기 그래서 그래, 당신은 레이아웃 변경에 대해 GUI를 알려 SwingUtilities.updateComponentTreeUI를 호출 할 수있는 방법이 updateComponentTreeUI

/** 
* A simple minded look and feel change: ask each node in the tree 
* to <code>updateUI()</code> -- that is, to initialize its UI property 
* with the current look and feel. 
*/ 
public static void updateComponentTreeUI(Component c) { 
    updateComponentTreeUI0(c); 
    c.invalidate(); 
    c.validate(); 
    c.repaint(); 
} 

의 코드이지만 큰 오버 헤드 (그리고 이론적으로 어떤 부작용이있을 수 있습니다). 귀하의 경우에는 revalidaterepaint의 조합이 좋습니다.

관련 문제