Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3957376
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:28:58+00:00 2026-05-20T02:28:58+00:00

I am writing a BlackBerry application that uses a custom title bar. Rather than

  • 0

I am writing a BlackBerry application that uses a custom title bar. Rather than using the textual based title bar, my application uses an image.

I am having trouble redrawing this title bar once the orientation of the device, such as a BlackBerry Storm or Torch, changes from portrait to landscape. See my code for my titleBar Class below.

Any help would be appreciated! Thanks!!

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

/**
 * Title Bar
 */

public class TitleBar extends Field implements DrawStyle
{
    private int fieldWidth;
    private int fieldHeight;
    private int fontColour;
    private int backgroundColor;

    private Bitmap bgImage = Bitmap.getBitmapResource("bgtitle.png");
    private Bitmap titleImage =  Bitmap.getBitmapResource("logotitle.png");
    private static final int BACKGROUND_COLOR = 0x00000000;


    public TitleBar() 
    {
        super(Field.NON_FOCUSABLE);
        fieldHeight = titleImage.getHeight();
        fieldWidth = Display.getWidth();

        //background color is black
        backgroundColor = BACKGROUND_COLOR;        
    }

    public void setBackgroundColour(int _backgroundColour)
    {
        backgroundColor = _backgroundColour;
        invalidate();
    }

    protected void layout(int width, int height) 
    {
        setExtent(getPreferredWidth(), getPreferredHeight());
    }

    public int getPreferredWidth() 
    {
        return fieldWidth;
    }

    public int getPreferredHeight() 
    {
        return fieldHeight;
    }

    protected void paint(Graphics graphics) 
    {

        int w = this.getPreferredWidth();
        int h = this.getPreferredHeight();

        int width_of_bg = 10;
        int paint_position = 0;

        int screen_width = Display.getWidth();
        while(paint_position<screen_width){
            graphics.drawBitmap(paint_position, 0, w, h, bgImage, 0, 0);
            paint_position += width_of_bg;
        }

        int marginX = (w- titleImage.getWidth() ) / 2 ; 
        graphics.drawBitmap(marginX, 0, w, h, titleImage, 0, 0);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:28:59+00:00Added an answer on May 20, 2026 at 2:28 am

    Solved it!

    It was because I was getting the width in the constructor. When the device was reoriented, I would retrieve the saved value which was taken in the constructor.

    Here is the fixed code:

    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.component.BitmapField;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.system.*;
    
    /**
     * Title Bar
     */
    
    public class TitleBar extends Field implements DrawStyle
    {
        private int fieldWidth;
        private int fieldHeight;
        private int fontColour;
        private int backgroundColor;
    
        private Bitmap bgImage = Bitmap.getBitmapResource("bgtitle.png");
        private Bitmap titleImage =  Bitmap.getBitmapResource("logotitle.png");
        private static final int BACKGROUND_COLOR = 0x00000000;
    
    
        public TitleBar() 
        {
            super(Field.NON_FOCUSABLE);
            fieldHeight = titleImage.getHeight();
            fieldWidth = Display.getWidth();
    
            //background color is black
            backgroundColor = BACKGROUND_COLOR;        
        }
    
        public void setBackgroundColour(int _backgroundColour)
        {
            backgroundColor = _backgroundColour;
            invalidate();
        }
    
        protected void layout(int width, int height) 
        {
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
    
        public int getPreferredWidth() 
        {
            return Display.getWidth();
        }
    
        public int getPreferredHeight() 
        {
            return fieldHeight;
        }
    
        protected void paint(Graphics graphics) 
        {
    
            int w = this.getPreferredWidth();
            int h = this.getPreferredHeight();
    
            int width_of_bg = 10;
            int paint_position = 0;
    
            while(paint_position<w){
                graphics.drawBitmap(paint_position, 0, w, h, bgImage, 0, 0);
                paint_position += width_of_bg;
            }
    
            int marginX = (w- titleImage.getWidth() ) / 2 ; 
            graphics.drawBitmap(marginX, 0, w, h, titleImage, 0, 0);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application in BlackBerry, where I want to do some custom
I am writing a Asp.net MVC 2 application that uses Forms Authentication and currently
I am writing an java based application for blackberry. Can anyone please tell me
I'm writing an app for Blackberry that was originally implemented in standard J2ME. The
I'm writing a little application for my BlackBerry and I need to send some
I'm writing a Blackberry app. I have a custom list field where I can
I'm writing a BlackBerry Java application and need it to submit a print request
I'm writing a BlackBerry app in Java using the BlackBerry Java API (OS 4.7
I am writing an app for the Blackberry Playbook using Flash Builder 4.6 and
I'm writing the HTML for a hybrid (iPhone/Android/Blackberry) mobile application. I'm not directly involved

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.