1

I'm trying to stylize a jTextPane using Java Synth and XML. I can apply a style to jPanes and to jButtons but cannot apply to jTextPanes. The problem is that the paint method paintTextPaneBackground (or even paintTextPaneBorder) in my custom painter is not called.

The XML code:

<?xml version="1.0" encoding="UTF-8"?>
<synth>


    <object id="painter" class="ui.themes.MyPainter" />

    <!-- BASIC -->
    <style id="basic">
        <font name="Helvetica" size="18" />

        <state>
            <color value="#ff0000" type="BACKGROUND" />
            <color value="#000000" type="FOREGROUND" />
            <opaque value="true" />
            <insets top="12" left="12" bottom="12" right="12" />

        </state>
    </style>
    <bind style="basic" type="region" key=".*" />

    <!-- PANE  -->
    <style id="panel">
        <painter method="panelBackground" idref="painter" />
    </style>
    <bind style="panel" type="region" key="Panel" />

    <!-- JBUTTON  -->
    <style id="button">
        <insets top="12" left="12" bottom="12" right="12" />
        <state>
            <color value="#212121" type="FOREGROUND" />
            <painter method="buttonBackground" idref="painter" />
        </state>
    </style>
    <bind style="button" type="region" key="BUTTON" />

    <!-- JTEXTPANE  -->
    <style id="textpane">       
        <insets top="12" left="12" bottom="12" right="12" />
        <state>
            <color value="#0000ff" type="BACKGROUND" />
            <color value="#212121" type="FOREGROUND" />
            <painter method="textPaneBackground" idref="painter" />
        </state>
    </style>
    <bind style="textpane" type="region" key="TEXT_PANE" />


</synth>

My custom painter:

    public class MyPainter extends SynthPainter {




    @Override
    public void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
        System.out.println("This method is called. :)");
    }   

    @Override
    public void paintPanelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
                System.out.println("This method is called. :)");
    }

    public void paintTextPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
                System.out.println("This method is NOT CALLED. :(");
    }

}

How can I apply a style to a jTextPane?

Chuck
  • 988
  • 7
  • 17
  • 30
user3788133
  • 83
  • 1
  • 6
  • Let me guess... You're using Nimbus L&F ? – Sharcoux Feb 22 '15 at 21:45
  • Not. Just SynthLookAndFeel class: SynthLookAndFeel laf = new SynthLookAndFeel(); laf.load(LaFTester.class.getResourceAsStream("laf.xml"), LaFTester.class); UIManager.setLookAndFeel(laf); – user3788133 Feb 22 '15 at 22:29

0 Answers0