Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could always try the Synth look &amp; feel. You provide an xml file that acts as a sort of stylesheet, along with any images you want to use. The code might look like this:</p> <pre><code>try { SynthLookAndFeel synth = new SynthLookAndFeel(); Class aClass = MainFrame.class; InputStream stream = aClass.getResourceAsStream("\\default.xml"); if (stream == null) { System.err.println("Missing configuration file"); System.exit(-1); } synth.load(stream, aClass); UIManager.setLookAndFeel(synth); } catch (ParseException pe) { System.err.println("Bad configuration file"); pe.printStackTrace(); System.exit(-2); } catch (UnsupportedLookAndFeelException ulfe) { System.err.println("Old JRE in use. Get a new one"); System.exit(-3); } </code></pre> <p>From there, go on and add your JButton like you normally would. The only change is that you use the setName(string) method to identify what the button should map to in the xml file.</p> <p>The xml file might look like this:</p> <pre><code>&lt;synth&gt; &lt;style id="button"&gt; &lt;font name="DIALOG" size="12" style="BOLD"/&gt; &lt;state value="MOUSE_OVER"&gt; &lt;imagePainter method="buttonBackground" path="dirt.png" sourceInsets="2 2 2 2"/&gt; &lt;insets top="2" botton="2" right="2" left="2"/&gt; &lt;/state&gt; &lt;state value="ENABLED"&gt; &lt;imagePainter method="buttonBackground" path="dirt.png" sourceInsets="2 2 2 2"/&gt; &lt;insets top="2" botton="2" right="2" left="2"/&gt; &lt;/state&gt; &lt;/style&gt; &lt;bind style="button" type="name" key="dirt"/&gt; &lt;/synth&gt; </code></pre> <p>The bind element there specifies what to map to (in this example, it will apply that styling to any buttons whose name property has been set to "dirt").</p> <p>And a couple of useful links:</p> <p><a href="http://javadesktop.org/articles/synth/" rel="noreferrer">http://javadesktop.org/articles/synth/</a></p> <p><a href="http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/synth.html" rel="noreferrer">http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/synth.html</a></p>
 

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