01-24-2011 01:00 PM
A design question, what is a good implementation of the following? I need to create a custom button that looks like:
----------- | Header | | Subheader | | Text | -----------
I know I can't add a VerticalFieldManager or add any field to a ButtonField, but if I create a custom button, how would I create three lines of text similar to having three LabelFields aligned in a VerticalFieldManager?
Solved! Go to Solution.
01-24-2011 01:12 PM - edited 01-24-2011 01:13 PM
I would suggest:
Create methods that save your 3 captions
Set the button's text to nothing
overriding layout so you can call your own setExtent() and give it the proper dimensions, as well as paint() so you can print the text out on your own (along with calling super.paint())
Override the getPreferred methods to return a proper dimension
I may be forgetting something here, but that sounds like enough to do it to me without actually trying it.
01-24-2011 01:24 PM
You can create a multi-line focusable label field by creating it with FOCUSABLE style bit and having newline characters in its text. It can be made to work much like a button field (override navigationClick / navigationUnclick to perform the action or, better yet, to invoke fieldChangeNotify so that you can hook up to the field with a FieldChangeListener).
Use RichTextField rather than LabelField if you want to play with fonts (say, bold underlined header; italic subheader; regular text).
If you want rounded corners and other effects, override the field's paintBackground or paint method (don't forget to call super.paint if you go with the latter).
Having said that - there is no single best design, so feel free to browse the forums (searching for "multiline" or "multi-line" yields quite a few results) and come up with your own ideas.