3

I have a label with some text and I want to have a few words in that text be a clickable HTML link. Is there any way to do this?

If not in a Label, is there a way to use the void paint(Graphics g) function to do this with raw drawing?

0

2 Answers 2

2

While I'm not certain, I don't think that can be done. However, I think this solution should do what you need:

See answer here: Clickable link in a label for codename one?

1

Use flow layout e.g.:

Form hi = new Form("Richtext", BoxLayout.y());

Button clickable = new Button("link", "Label");
clickable.getAllStyles().setTextDecoration(Style.TEXT_DECORATION_UNDERLINE);

hi.add(FlowLayout.encloseMiddle(new Label("This"), new Label("is"), new Label("a"), clickable, new Label("to"), new Label("click")));
clickable.addActionListener(e -> ToastBar.showMessage("Click", FontImage.MATERIAL_INFO));

hi.show();

enter image description here

4
  • Ok thanks, this looks like it might work. My concern is that there is an unnatural amount of space between the labels. Is there any way to squeeze the labels together a bit more so that it appears like a line of text?
    – Marc
    Feb 17, 2017 at 6:21
  • That's padding/margin. You can tune that
    – Shai Almog
    Feb 17, 2017 at 6:28
  • How exactly can I tune this? FlowLayout in codename one does not have gaps that can be set. Can you please point me to the methods I can use?
    – Marc
    Feb 17, 2017 at 17:00
  • Never mind, I figured it out. You set the margin and padding to zero using style for the lements you are putting inside the FlowLayout. For the text on the left I used style=textField.getAllStyles() and then style.setMarginRight(0) and setPaddingRight(0). Also did this for left margin and padding on the button on the right.
    – Marc
    Feb 17, 2017 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.