Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
jtp5120
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
Accepted Solution

How do I design a custom button that has three rows of text inside the button itself?

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?

 

Thanks.

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: How do I design a custom button that has three rows of text inside the button itself?

[ Edited ]

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.

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: How do I design a custom button that has three rows of text inside the button itself?

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.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!