SynthPainter

SynthPainter (JComponent 영역 페인터)

JComponent의 일부 영역을 그리는 데 사용되는 페인터 클래스입니다. 최소한 각 JComponent는 두 개의 그리기 메서드(테두리용, 배경용)를 가지며, Region이 여러 개인 컴포넌트는 그만큼 더 많은 그리기 메서드를 가집니다.

SynthPainter 인스턴스는 SynthStyle.getPainter(javax.swing.plaf.synth.SynthContext) 메서드로 얻습니다. 보통 Synth 파일 형식으로 등록합니다.

출처: Java API Reference

본문

다음 예시는 모든 JButton에 대해 myImage.png 이미지를 렌더링하는 페인터를 등록합니다.


<style id="buttonStyle">

  <imagePainter path="myImage.png" sourceInsets="2 2 2 2" paintCenter="true" stretch="true"/>

  <insets top="2" bottom="2" left="2" right="2"/>

</style>

<bind style="buttonStyle" type="REGION" key="button"/>

SynthPainter는 실제로 그리기를 수행하지 않는 추상 클래스입니다. 모든 메서드가 비어 있습니다. 어떤 메서드도 예외를 던지도록 타입이 지정되지는 않았지만, 하위 클래스는 유효한 인자가 전달된다고 가정할 수 있으며, 유효하지 않은 인자가 들어오면 NullPointerException이나 IllegalArgumentException을 던질 수 있습니다.

주요 그리기 메서드로는 paintArrowButtonBackground/Border, paintButtonBackground/Border, paintCheckBoxBackground/Border, paintComboBoxBackground/Border, paintDesktopIconBackground/Border, paintLabelBackground, paintMenuBackground/Border, paintPanelBackground/Border, paintProgressBarBackground/Foreground, paintScrollBarBackground/Border/ThumbBackground/TrackBackground, paintSliderBackground/Border/ThumbBackground/TrackBackground, paintSplitPaneDividerBackground, paintTabbedPaneBackground/Border/TabBackground/TabBorder, paintTextFieldBackground/Border, paintToolBarBackground/Border, paintTreeBackground/Border 그리고 paintViewportBackground 등이 있습니다.

생성자는 protected SynthPainter()로 하위 클래스에서 호출합니다.

더 알아보기 (Learn more)

Java 공식 API