我的InteractionDialog
有一个TextField
。我将TextField
样式设置为CSS中定义的UIID。显示TextField
背景,但不显示其中的文字
虽然
System.err.println("The textfield contains " + nameTf.getText());
按预期打印预期文本,前景色为0。只有在我按下TextField内部时才会显示文字,但是当我在外面按下它时会消失,如下所示:
控制台中没有出现EDT违规行为。
使用的代码如下:
// Opens a dialog to input the name
nameButton.addActionListener((evt) -> {
InteractionDialog nameDialog = new InteractionDialog();
nameDialog.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));
// Hint for the user
SpanLabel hintLabel = new SpanLabel("Indiquer un nom");
hintLabel.setTextUIID(hintStyleName);
TextField nameTf = new TextField(
chosenAlarm.name.get() == null ? "Ma destination préférée" : chosenAlarm.name.get()
);
nameTf.setUIID(textFieldStyleName);
System.err.println("The textfield colour is " + nameTf.getUnselectedStyle().getFgColor());
// Validate text button
Button validateNameButton = new Button("Valider >");
validateNameButton.setUIID("ValidateButton");
Container nameButtons = BoxLayout.encloseX(validateNameButton);
validateNameButton.addActionListener((e) -> {
// ...
});
nameDialog.addComponent(BorderLayout.CENTER, nameTf);
nameDialog.addComponent(BorderLayout.NORTH, hintLabel);
// The buttons will be centered
nameDialog.addComponent(BorderLayout.SOUTH, BorderLayout.centerCenter(nameButtons));
// Shows the dialog in the center of the screen
nameDialog.showPopupDialog(nameButton);
});
所以似乎只要TextField
失去焦点,文本就会消失。即使用户未在TextField
内按压,我该怎么做才能显示TextField
中包含的文字?
请注意:屏幕截图隐藏了一些元素,因为应用程序是最高机密的NSA级别; - )。
任何帮助表示赞赏,
答案 0 :(得分:2)
实际上问题来自于我将不透明度设置为255的css样式(就像主题设计器中的透明度一样)。它必须设置为0到1.0之间的值。
MyTextFiledStyle {
color: #000000;
background-color: #ffffff;
text-align: left;
opacity: 1.0; /*NOT 255 */
font-family: "native:MainLight";
}