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

时间:2018-04-29 16:55:25

标签: codenameone

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

no text appearing in the text field

虽然

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

按预期打印预期文本,前景色为0。只有在我按下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级别; - )。

任何帮助表示赞赏,

1 个答案:

答案 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"; 

}