codenameone - 仅当 TextField 具有焦点时才显示 InteractionDialog 中的 Textfield 文本

标签 codenameone

在我的 InteractionDialog 中,有一个 TextField。我将 TextField 样式设置为 CSS 中定义的 UIID。显示了 TextField 背景,但不显示其中的文本

no text appearing in the text field

虽然

    System.err.println("The textfield contains " + nameTf.getText()); 

打印预期的文本,前景色按预期为 0。仅当我在 TextField 内部按下时,文本才会显示,但一旦在 TextField 外部按下,文本就会消失,如下所示:

text only appears when TextField has focus

控制台中没有出现 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 绝密级别;-)。

感谢任何帮助,

最佳答案

实际上,问题来自于 css 样式,我将不透明度设置为 255(就像在具有透明度的主题设计器中一样)。它确实必须设置为 0 到 1.0 之间的值。

MyTextFiledStyle {
color: #000000; 
background-color: #ffffff;
text-align: left;
opacity: 1.0; /*NOT 255 */
font-family: "native:MainLight"; 

}

关于codenameone - 仅当 TextField 具有焦点时才显示 InteractionDialog 中的 Textfield 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50089110/

相关文章:

java - 错误 "import static com.sun.corba (...)"

android - 在 Codename One 应用程序中显示 Android LinearLayout

java - 代号一-如何检查BubbleTransition支持

java - 如何从 android native 代码调用 ShowForm?

android - 代号一。 IOS 拦截 URL 问题。

codenameone - 新代号 One 准系统项目开始新项目

codenameone - 代号一号中的股票行情模式

java - lwuit向导并部署

java - CodeNameOne 将图像上传到 servlet 时出现 StateMachine 问题

firebase - 在2020年3月1日之前切换到Play Referrer API-Google Play