Java jTextPane的自定义画师不工作
我正在尝试使用JavaSynth和XML对jTextPane进行样式化。我可以将样式应用于jPanes和jButtons,但不能应用于jTextPanes。问题是在我的自定义画师中没有调用paintTextPaneBackground(甚至paintTextPaneBorder)的绘制方法 XML代码:Java jTextPane的自定义画师不工作,java,xml,styles,jtextpane,synth,Java,Xml,Styles,Jtextpane,Synth,我正在尝试使用JavaSynth和XML对jTextPane进行样式化。我可以将样式应用于jPanes和jButtons,但不能应用于jTextPanes。问题是在我的自定义画师中没有调用paintTextPaneBackground(甚至paintTextPaneBorder)的绘制方法 XML代码: <?xml version="1.0" encoding="UTF-8"?> <synth> <object id="painter" class="u
<?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>
如何将样式应用于jTextPane?让我猜猜。。。你用的是Nimbus L&F?不是。只是SynthLookAndFeel类:SynthLookAndFeel laf=newsynthLookandFeel();load(LaFTester.class.getResourceAsStream(“laf.xml”),LaFTester.class);UIManager.setLookAndFeel(laf);
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. :(");
}
}