LWUIT, How to create a custom label for form title
-
24-05-2021 - |
سؤال
I want to know how to create a label that contains two icons, one on each side and set it as the title bar for the form element (LWUIT widgets).
المحلول
Form has a function to get a titleArea then you can put some components what you want.
Form f = new Form();
Container c = f.getTitleArea();
Label iconLabel1 = new Label("leftIcon");//using Image
Label iconLabel2 = new Label("rightIcon");//using Image
c.addComponent(BorderLayout.WEST, iconLabel1);
c.addComponent(BorderLayout.EAST, iconLabel2);
نصائح أخرى
You can just add a component to the north portion of the screen which is the recommended way that will work properly and won't break for newer versions of LWUIT/Codename One.
When you don't set a title it will just work and you can give it the Title UIID. LWUIT 1.5 and newer have a TitleArea container but I suggest you stay away from it since CodenameOne customizes it quite allot for iOS/Android 4.x etc.
Use the setTitleComponent(Label title)
method.
EDIT :
Derive the Label
class and implement the paint
method where you can use the Graphics
method to draw Image
s and texts. Also set the label's text position to Label.CENTER
.