jTextPane的自定义画家无法正常工作

时间:2015-02-21 23:55:50

标签: java xml styles jtextpane synth

我尝试使用 Java Synth 和XML来设置 jTextPane 的样式。我可以将样式应用于 jPanes jButtons ,但不能应用于jTextPanes。问题是我的自定义画家中的paint方法 paintTextPaneBackground (甚至paintTextPaneBorder)没有被调用。

XML代码:

<?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>

我的自定义画家:

    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. :(");
    }

}

如何将样式应用于jTextPane?

0 个答案:

没有答案