在我的 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级别;-) .
任何帮助,赞赏,
1 回答
实际上问题来自于css样式,我将不透明度设置为255(就像在具有透明度的主题设计器中一样) . 它必须设置为0到1.0之间的值 .
}