I can't get a white background for my JTextField, what am I doing wrong ? (I know that the image is not painted in the center for the text to be shown, but I'va set background to white; has no effect)
-- XML --
<synth>
<style id="textfield">
<state>
<font name="Verdana" size="12" />
<color value="black" type="TEXT_FOREGROUND" />
<color value="white" type="TEXT_BACKGROUND" />
<color value="white" type="BACKGROUND" />
</state>
<imagePainter method="textFieldBorder" path="images/ch_textfield.png"
sourceInsets="4 6 4 6" paintCenter="false" />
<insets top="4" left="6" bottom="4" right="6" />
</style>
<bind style="textfield" type="region" key="TextField" />
</synth>
-- Java --
public class SynthCh extends JApplet {
public void init() {
try {
initLookAndFeel();
} catch (Exception ex) {
ex.printStackTrace();
}
setSize(300, 50);
initUi();
}
public void initUi() {
JPanel jpMain = new JPanel();
jpMain.setName("Root");
JTextField textField = new JTextField(10);
jpMain.setLayout(new FlowLayout());
this.add(jpMain);
jpMain.add(textField, BorderLayout.NORTH);
}
public static void initLookAndFeel() {
SynthLookAndFeel lookAndFeel = new SynthLookAndFeel();
try {
lookAndFeel.load(SynthCh.class.getResourceAsStream("synthCh.xml"),
SynthCh.class);
UIManager.setLookAndFeel(lookAndFeel);
} catch (Exception e) {
e.printStackTrace();
}
}
}
A background cannot be rendered on components that are transparent by default.
Add <opaque value="TRUE"/>
at the beginning of your style.