Is there a better way to add a tick/cross to a text field ?

        Form hi = new Form("Badge");
        
        Button chat = new Button("");
        FontImage.setMaterialIcon(chat, FontImage.MATERIAL_CHAT, 7);
        Label badge = new Label("33");
        badge.getAllStyles().setBorder(RoundBorder.create().rectangle(true
));
        badge.getAllStyles().setAlignment(Component.CENTER);
        int size = Display.getInstance().convertToPixels(1.5f);
        badge.getAllStyles().setFont(Font.createTrueTypeFont(
"native:MainLight", "native:MainLight").derive(size, Font.STYLE_PLAIN));
        Container cnt = LayeredLayout.encloseIn(chat, FlowLayout.
encloseRight(badge));
        cnt.setLeadComponent(chat);
        
        hi.add(cnt);

        TextField changeBadgeValue = new TextField("33");
        changeBadgeValue.addDataChangedListener((i, ii) -> {
            badge.setText(changeBadgeValue.getText());
            cnt.revalidate();
        });
        
        Font materialFont = FontImage.getMaterialDesignFont();
        int h = changeBadgeValue.getPreferredH() / 2;
        FontImage tick = FontImage.createFixed("" + FontImage.MATERIAL_CHECK
, materialFont, 0x00ff00, h, h);
        FontImage cross = FontImage.createFixed("" + FontImage.
MATERIAL_CLOSE, materialFont, 0xff0000, h, h);
        
        Label verify = new Label();
        verify.getAllStyles().setAlignment(Component.CENTER);
        verify.setIcon(cross);
        
        Container cnt1 = LayeredLayout.encloseIn(changeBadgeValue, 
FlowLayout.encloseRight(verify));
        cnt1.setLeadComponent(changeBadgeValue);
        
        hi.add(cnt1);
        
        hi.show();


-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/13209211-63ec-46ed-ba3f-e57f2ab772be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to