Java Synth:无法在文本字段中获得白色背景
我的 JTextField 无法获得白色背景,我做错了什么? (我知道图像没有画在要显示的文本的中心,但我将背景设置为白色;没有效果)
-- 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();
}
}
}
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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下透明的组件上无法渲染背景。
在样式的开头添加
。A background cannot be rendered on components that are transparent by default.
Add
<opaque value="TRUE"/>
at the beginning of your style.