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
Posts: 51
Registered: ‎11-27-2008
My Device: Not Specified
Accepted Solution

Multi-Line ButtonField

Is it possible to add more than one Label-Line to a Buttonfield?

 

Searching for a while, but was not able to found sth. similar....

 

dognose

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Multi-Line ButtonField

The standard ButtonField does not support multi-line labels.

 

Create you own ButtonField via extending the standard class and implementing the necessary functionality.

Highlighted
Developer
Posts: 51
Registered: ‎11-27-2008
My Device: Not Specified

Re: Multi-Line ButtonField

ok, i thought that :-)

 

i created already a class, that overrides the getPreferredWidth() and getPreferredHeight() method,

but i dont know, what i have to override for the label....

 

final public class TrackButton extends ButtonField{ public TrackButton(String label, long style) { super(label, style); } public int getPreferredWidth(){ Screen sr = UiApplication.getUiApplication().getActiveScreen(); return sr.getWidth(); } public int getPreferredHeight(){ return 65; } }

 

Any hint for me? :-)

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Multi-Line ButtonField

You should override paint() method and draw two/more lines of text via graphics.drawText()

 

do not forget to invoke super.paint() before.

Developer
Posts: 51
Registered: ‎11-27-2008
My Device: Not Specified

Re: Multi-Line ButtonField

okay, i'll try.

 

thx for hint

Developer
Posts: 51
Registered: ‎11-27-2008
My Device: Not Specified

Re: Multi-Line ButtonField

okay, i found a solution for that.

 

But i still dont know, what u mean with "invoke super.paint() first"...

i tried this, but then i get the message, that paint isnt a member of super....

 

anyway, this way it works (okay, its a "little" extendet button) (part of a playlist generater tool^^):

 

final public class TrackButton extends ButtonField implements DrawStyle{ private int _id; private String _artist; private String _album; private String _title; public TrackButton(int id, String title, String artist, String album, long style) { super(style); _id = id; _artist = artist; _title = title; _album = album; } public int getId(){ return _id; } public String getArtist(){ return _artist; } public String getAlbum(){ return _album; } public String getTitle(){ return _title; } public int getPreferredWidth(){ Screen sr = UiApplication.getUiApplication().getActiveScreen(); return sr.getWidth(); } public int getPreferredHeight(){ return 65; } protected void drawFocus(Graphics graphics, boolean on){ graphics.invert(1, 1, getWidth() - 2, getHeight() - 2); } protected void paint(Graphics g){ g.drawRect(0,0,this.getWidth(),this.getHeight()); g.drawText(_id + ".) " + _title, 0,0,0,this.getWidth()); g.drawText(_artist + "/" + _album, 0,20,0,this.getWidth()); } }

 

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Multi-Line ButtonField

When you call super.paint(g); you call the parent class drawing functionality.

 

Sometimes it is necessary.

Developer
Posts: 51
Registered: ‎11-27-2008
My Device: Not Specified

Re: Multi-Line ButtonField

okay, but with the code above, the ButtonFields draw function seems to be called anyway... (bg is set,

without manually drawing it) - or doesnt the bg dont belong to the draw() mehtod?

 

thx for your help.

dognose

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Multi-Line ButtonField

there are two methods:

 

paint() and paintBackground()

 

if you need to take control over background painting - override paintBackground() method

Developer
Posts: 51
Registered: ‎11-27-2008
My Device: Not Specified

Re: Multi-Line ButtonField

[ Edited ]

okay, the api dont know the ButtonField.drawpaintBackground() method.... so i cant find it...

 

is there a method to find out, what methods a field normaly uses, and can be overwriten?

 

(im in search of sth like the drawOnClick() - my buttons currently fall back to the normal button style,

while clicking on em)

dognose

Message Edited by dognose on 11-30-2008 02:14 PM