JComboBox UI는 텍스트 필드, 목록 및 화살표로 구성됩니다. 당신은 어떤 준비가 L & F를 사용하거나 신디 L로 가장 쉽게 구현할 수 있습니다 맞게 사용자 정의 & F.
초기화 L & F :
SynthLookAndFeel lookAndFeel = new SynthLookAndFeel();
try {
lookAndFeel.load(YourClassAlongWithSynthXml.class.getResourceAsStream("synth.xml"), YourClassAlongWithSynthXml.class);
} catch (ParseException e) {
e.printStackTrace();
}
UIManager.setLookAndFeel(lookAndFeel);
synth.xml이 같은 포함
:
를
<style id="textfield">
<insets top="4" left="6" bottom="4" right="6" />
<state>
<font name="Verdana" size="12" />
<!--
<color type="BACKGROUND" value="#D2DFF2" />
-->
<color type="TEXT_FOREGROUND" value="#003c2d" />
</state>
<imagePainter method="textFieldBorder" path="images/textfield.png" sourceInsets="4 6 4 6" paintCenter="false" />
</style>
<bind style="textfield" type="region" key="TextField" />
<style id="arrowStyle">
<imagePainter method="arrowButtonForeground" path="images/arrow-up.png" sourceInsets="0 0 0 0" stretch="false" direction="north" />
<imagePainter method="arrowButtonForeground" path="images/arrow-down.png" sourceInsets="0 0 0 0" stretch="false" direction="south" />
<imagePainter method="arrowButtonForeground" path="images/arrow-left.png" sourceInsets="0 0 0 0" stretch="false" direction="west" />
<imagePainter method="arrowButtonForeground" path="images/arrow-right.png" sourceInsets="0 0 0 0" stretch="false" direction="east" />
</style>
<bind key="ArrowButton" type="region" style="arrowStyle" />
<style id="comboArrowStyle">
<imagePainter method="arrowButtonForeground" path="images/combobox-arrow.png" sourceInsets="0 0 0 0" stretch="false" direction="south" />
</style>
Synth L & F를 사용하면 UI 구성 요소의 모양을 완전히 정의해야합니다.
하지만 당신은 단지 기본 L & F를 재사용 색상을 수정해야하는 경우, 당신은 콤보 상자의 UI 초기화 다음 조각을 사용할 수 있습니다 : 당신이 전체를 만들지 않으려면
final Color COLOR_BUTTON_BACKGROUND = Color.decode("#d3dedb");
UIManager.put("ComboBox.buttonBackground", COLOR_BUTTON_BACKGROUND);
UIManager.put("ComboBox.buttonShadow", COLOR_BUTTON_BACKGROUND);
UIManager.put("ComboBox.buttonDarkShadow", COLOR_BUTTON_BACKGROUND);
UIManager.put("ComboBox.buttonHighlight", COLOR_BUTTON_BACKGROUND);
답변을 찾았습니까? –
@Stephane, 나는 맞춤 구성 요소를 만들었습니다. –
동일한 문제가 발생했습니다 ... 맞춤 구성 요소를 공유 할 수 있습니까? – sirbris