Change the font color

I’m learning how to program in MicroEJ making some samples, now I’m trying to change the font color but the program don’t recongnize setForecolor command to use.

public static void main(String[] args) {
		MicroUI.start();
		Desktop d = new Desktop();

		Label lbl1 = new Label("This is an example using flow container"); //$NON-NLS-1$
		Label lbl2 = new Label("flow container can be used in vertical or horizontal position"); //$NON-NLS-1$
		Label lbl3 = new Label("as you wish use"); //$NON-NLS-1$

		// style
		CascadingStylesheet stylesheet = new CascadingStylesheet();
		EditableStyle style = stylesheet.getSelectorStyle(new TypeSelector(Label.class));
		Font font = Font.getFont("/Fonts/AlarmClockFont.ejf");

		style.setFont(font);
		style.setBorder(new RectangularBorder(Colors.PURPLE, 2));
		style.setBackground(new ImageBackground(Image.getImage("/images/NLights.png")));

		// flow container
		Flow flowContainer = new Flow(LayoutOrientation.VERTICAL);
		flowContainer.addChild(lbl1);
		flowContainer.addChild(lbl2);
		flowContainer.addChild(lbl3);

		d.setStylesheet(stylesheet);
		d.setWidget(flowContainer);
		d.requestShow();

	}
}

Hello oderlan,

glad to have you using MicroEJ!

To set the text color of your Label widgets, you can call the setColor() method on the style instance.
For example, in your case:

	style.setFont(font);
	style.setColor(Colors.RED);
	style.setBorder(new RectangularBorder(Colors.PURPLE, 2));
	style.setBackground(new ImageBackground(Image.getImage("/images/NLights.png")));

The Label widgets will display red texts.

You can check the complete API of the EditableStyle class here: EditableStyle

There is also a comprehensive tutorial to get started with UI on our documentation website, it addresses this point too: Style — MicroEJ Documentation

Hope it helps!

Thomas for MicroEJ

Thank you so much for your help Thomas.