BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-21-2008, 12:24 AM   #1
Pan_magically
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8100
PIN: N/A
Carrier: Hong Kong CSL
Posts: 18
Wink Alpha value of color not working in paint()

Please Login to Remove!

Trying to display a hovering label on top of my ListField. The Label should be a round-rect and has a semi-transparent black bgcolor. I got the label and text to display and everything, but the bgcolor is solid black. The idea is that the hovering label will appear on top of the items in ListField.


here is my code
Code:
public class MyListField extends ListField {


    protected void paint(Graphics g){
        super.paint(g);
        if(this.getSize() > 0)        
            this.paintFloatingText(g);
    }

    protected int getVerticalScroll(){
        Manager manager = this.getManager();
        int scrollPos = -1;
        if(manager != null)
            scrollPos = manager.getVerticalScroll();

             
        return scrollPos;                
    }
    
    private void paintFloatingText(Graphics g){

	XYRect floatingRect = new XYRect(100,100,70,30);
        
        // since the Field is scrollable, a y offset is need to make sure the label     always displays on the same position on the screen
        int offset_x = 0;
        int offset_y = this.getVerticalScroll();
        
  
        Font fnt = this.floatingLabelFont;
        
        //g.setColor(UIParameters.floating_label_bgColor);
        // set the color as black semi-transparent fror background 
        g.setColor(0xCC000000);
        
        int arc = Math.min(floatingRect.width,floatingRect.height)/2;        
        g.fillRoundRect(offset_x + floatingRect.x ,offset_y + floatingRect.y, floatingRect.width,floatingRect.height,arc,arc);

        //g.setColor(UIParameters.floating_label_fgColor);
        // set the color as white for text 
        g.setColor(0x00FFFFFF);
        
        g.setFont(fnt);

        // Calculate the left-top margins to center the text display
        int margin_x = (int)((floatingRect.width - fnt.getAdvance(this.label))/2);           
        int margin_y = (int)((floatingRect.height - fnt.getHeight())/2);        
        g.drawText(this.label, offset_x + floatingRect.x+margin_x, offset_y + floatingRect.y + margin_y, Graphics.TOP | Graphics.LEFT); 
    }    
}

Last edited by Pan_magically; 05-21-2008 at 12:29 AM..
Offline  
Old 05-21-2008, 12:58 AM   #2
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Use the get/setGlobalAlpha methods to handle transparency. So in your example you'd do something like:

graphics.setGlobalAlpha(0xCC);
graphics.setColor(0x000000);
// do stuff
// restore global alpha and color
__________________
Do your homework and know how to ask a good question.
Offline  
Old 05-21-2008, 02:01 AM   #3
Pan_magically
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8100
PIN: N/A
Carrier: Hong Kong CSL
Posts: 18
Default

Tyvm. It is working nicely now.

I am more used to using the j2me original Graphics object to draw stuff, and I didn't think a separate method was needed.
Offline  
Old 05-21-2008, 07:57 AM   #4
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

The setColor methods of the RIM graphics object do not take the first 8 bits (alpha) into account.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


4 Count Case GE ProLine 2 Bulb 120V T12 Electronic Fluorescent Light Ballasts picture

4 Count Case GE ProLine 2 Bulb 120V T12 Electronic Fluorescent Light Ballasts

$49.99



ADVANCE RQM-2S40-TP-WS 2-40T12RS BALLAST - 2 LIGHT 40 WATT RAPID START-LOT OF 5 picture

ADVANCE RQM-2S40-TP-WS 2-40T12RS BALLAST - 2 LIGHT 40 WATT RAPID START-LOT OF 5

$149.99



72C5081NP Philips Advance M130 HID Metal Halide Ballast 120/277V picture

72C5081NP Philips Advance M130 HID Metal Halide Ballast 120/277V

$199.99



Philips ADVANCE AmbiStar RELB-2S40-N Replacement Ballast 40-Watt 2-Lamp T12 picture

Philips ADVANCE AmbiStar RELB-2S40-N Replacement Ballast 40-Watt 2-Lamp T12

$18.79



10-Count GE Fluorescent Ballast, GE432-MVPS-L Electronic T8, 120v to 277v picture

10-Count GE Fluorescent Ballast, GE432-MVPS-L Electronic T8, 120v to 277v

$108.99



QHE 4X32T8/UNV ISH-SC Sylvania 51347 4-Lamp T8 Instant Start Fluorescent Ballast picture

QHE 4X32T8/UNV ISH-SC Sylvania 51347 4-Lamp T8 Instant Start Fluorescent Ballast

$10.79







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.