Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>JComboBox UI is composed from textfield, list and arrows. To customize them you can use some ready L&amp;F or implement your most easily with Synth L&amp;F.</p> <p>Initialize L&amp;F:</p> <pre><code>SynthLookAndFeel lookAndFeel = new SynthLookAndFeel(); try { lookAndFeel.load(YourClassAlongWithSynthXml.class.getResourceAsStream("synth.xml"), YourClassAlongWithSynthXml.class); } catch (ParseException e) { e.printStackTrace(); } UIManager.setLookAndFeel(lookAndFeel); </code></pre> <p>Where synth.xml contains something like this:</p> <pre><code>&lt;style id="textfield"&gt; &lt;insets top="4" left="6" bottom="4" right="6" /&gt; &lt;state&gt; &lt;font name="Verdana" size="12" /&gt; &lt;!-- &lt;color type="BACKGROUND" value="#D2DFF2" /&gt; --&gt; &lt;color type="TEXT_FOREGROUND" value="#003c2d" /&gt; &lt;/state&gt; &lt;imagePainter method="textFieldBorder" path="images/textfield.png" sourceInsets="4 6 4 6" paintCenter="false" /&gt; &lt;/style&gt; &lt;bind style="textfield" type="region" key="TextField" /&gt; &lt;style id="arrowStyle"&gt; &lt;imagePainter method="arrowButtonForeground" path="images/arrow-up.png" sourceInsets="0 0 0 0" stretch="false" direction="north" /&gt; &lt;imagePainter method="arrowButtonForeground" path="images/arrow-down.png" sourceInsets="0 0 0 0" stretch="false" direction="south" /&gt; &lt;imagePainter method="arrowButtonForeground" path="images/arrow-left.png" sourceInsets="0 0 0 0" stretch="false" direction="west" /&gt; &lt;imagePainter method="arrowButtonForeground" path="images/arrow-right.png" sourceInsets="0 0 0 0" stretch="false" direction="east" /&gt; &lt;/style&gt; &lt;bind key="ArrowButton" type="region" style="arrowStyle" /&gt; &lt;style id="comboArrowStyle"&gt; &lt;imagePainter method="arrowButtonForeground" path="images/combobox-arrow.png" sourceInsets="0 0 0 0" stretch="false" direction="south" /&gt; &lt;/style&gt; </code></pre> <p>With Synth L&amp;F you will need to fully define how your UI components look like you can't just.</p> <p>But if you just need to simply modify colors reusing your default L&amp;F, you can use the following snippets to initialize UI of combo box:</p> <pre><code>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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload