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
Contributor
Posts: 44
Registered: ‎07-27-2010
My Device: Tour
My Carrier: Verizon Wireless

adding icon to PillButtonField in "Advanced UI.." article

hi all, can someone please give me some tips on adding the capability

to add icons to PillButtonFiled so that the results looks like tabs with icons/text

 

i imagine it will be in one or more of these 3 methods in PillButtonField

 

BTW: i can't tell you all how much I appreciate all the samples, kb articles, responses to posts,

we have many users who have bb phones and all this help here in the bb java develoment area

 puts us in a position to let our customers keep and purchase additional

bb devices instead of the using the other smart phones available.

 

 

 

protected void paint( Graphics g )
    {
        int oldColour = g.getColor();
        try {
            int foregroundColor;
            if ( _pressed || _selected  ) {
                foregroundColor = COLOUR_TEXT_SELECTED;
            } else if( g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ) {
                foregroundColor = COLOUR_TEXT_FOCUS;
            } else {
                foregroundColor = COLOUR_TEXT;
            }
            
            g.setColor( foregroundColor );
            g.drawText( _text, 0, YPADDING, DrawStyle.HCENTER, _width ); 
        } finally {
            g.setColor( oldColour );
        }
    }
    
    protected void paintBackground( Graphics g )
    {
        int oldColour = g.getColor();
        
        int backgroundColor;
        int borderColor;
        
        if( _pressed ) {
            backgroundColor = COLOUR_BACKGROUND_SELECTED;
            borderColor = COLOUR_BORDER_SELECTED;
        } else if ( g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ) {
            backgroundColor = COLOUR_BACKGROUND_FOCUS ;
            borderColor = COLOUR_BORDER_FOCUS;
        }else if( _selected ) {
            backgroundColor = COLOUR_BACKGROUND_SELECTED;
            borderColor = COLOUR_BORDER_SELECTED;
        } else {
            backgroundColor = COLOUR_BACKGROUND;
            borderColor = COLOUR_BORDER;
        }
        
        try {
            if( _drawPosition == 0 ) {
                // Left
                drawButtonBackground( g, 0, 0, getWidth() + CORNER_RADIUS, getHeight(), backgroundColor, borderColor );
                drawSeparator( g, 0, 0, getWidth(), getHeight(), false, true );
            } else if( _drawPosition == 1 ) {
                // Right 
                drawButtonBackground( g, -CORNER_RADIUS, 0, getWidth() + CORNER_RADIUS, getHeight(), backgroundColor, borderColor );
                drawSeparator( g, 0, 0, getWidth(), getHeight(), true, false );
            } else if( _drawPosition == 2 ) {
                // Middle
                drawButtonBackground( g, -CORNER_RADIUS, 0, getWidth() + 2 * CORNER_RADIUS, getHeight(), backgroundColor, borderColor );
                drawSeparator( g, 0, 0, getWidth(), getHeight(), true, true );
            } else {
                // Single
                drawButtonBackground( g, 0, 0, getWidth(), getHeight(), backgroundColor, borderColor );
            }
            
        } finally {
            g.setColor( oldColour );
        }
    }
    
    private void drawButtonBackground( Graphics g, int x, int y, int width, int height, int backgroundColor, int borderColor )
    {
        int oldAlpha = g.getGlobalAlpha();
        try {
            g.setColor( backgroundColor );
            g.fillRoundRect( x, y, width, height, CORNER_RADIUS, CORNER_RADIUS );
            
            g.setGlobalAlpha( 0x44 );
            g.setColor( 0xFFFFFF ); // White highlight
            g.drawRoundRect( x, _selected ? y : y + 1, width, _height - 1, CORNER_RADIUS, CORNER_RADIUS );
            g.setColor( 0x000000 ); // Black lowlight
            g.drawRoundRect( x, _selected ? y + 1: y, width, height - 1, CORNER_RADIUS, CORNER_RADIUS );
            
            g.setGlobalAlpha( 0xFF );
            g.setColor( borderColor );
            g.drawRoundRect( x, y, width, height, CORNER_RADIUS, CORNER_RADIUS );
        } finally {
            g.setGlobalAlpha( oldAlpha );
        }
    }