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 4626006
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:21:20+00:00 2026-05-22T03:21:20+00:00

I’m trying to make a menu with an absolute layout that contains custom items

  • 0

I’m trying to make a menu with an absolute layout that contains custom items extending Field. This items show well in the HorizontalFieldManager for example, but with the AbsoluteFieldManager it just shows a blank screen.

This is my code so far:

/********************
 * CustomField.java *
 ********************/

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Keypad;

public class CustomField extends Field {
    Bitmap img;
    String s1, s2;
    Font font;
    int textColorUnfocused, textColorFocused, bgColorUnfocused, bgColorFocused;

    public CustomField(long style) {
        super(style);
    }

    public CustomField(Bitmap img, String s1, String s2) {// , long style) {
        // super(style);
        this.img = img;
        this.s1 = s1;
        this.s2 = s2;
        this.font = Font.getDefault();
        textColorUnfocused = 0x000000;
        textColorFocused = 0xffffff;
        bgColorUnfocused = 0xffffff;
        bgColorFocused = 0x3956F7;
    }

    protected void layout(int maxWidth, int maxHeight) {
        Font font = getFont();
        int width = img.getWidth() + 10;
        int height = img.getHeight() + (font.getHeight() * 3);
        setExtent(Math.min(width, maxWidth), Math.min(height, maxHeight));

    }

    protected void onFocus(int direction) {

        super.onFocus(direction);
        invalidate();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        invalidate();
    }

    public boolean isFocusable() {
        return true;
    }

    protected void paint(Graphics g) {

        // Draw background
        g.setColor(isFocus() ? bgColorFocused : bgColorUnfocused);
        g.fillRect(0, 0, getWidth(), getHeight());
        // draw image
        g.drawBitmap(5, 5, img.getWidth(), img.getHeight(), img, 0, 0);

        g.setColor(isFocus() ? textColorFocused : textColorUnfocused);
        // draw text
        g.drawText(s1, ((img.getWidth() + 10) / 2) - (font.getAdvance(s1) / 2),
                img.getHeight() + font.getHeight());
        g.drawText(s2, ((img.getWidth() + 10) / 2) - (font.getAdvance(s2) / 2),
                img.getHeight() + (2 * font.getHeight()));

    }

    protected boolean keyChar(char character, int status, int time) {
        if (character == Keypad.KEY_ENTER) {
            fieldChangeNotify(0);
            return true;
        }
        return super.keyChar(character, status, time);
    }

    public int getY() {

        return img.getHeight() + (font.getHeight() * 3);
    }

    public int getX() {
        return img.getWidth();
    }

}    

 /**************
 * MyApp.java *
 **************/
import net.rim.device.api.ui.UiApplication;


public class MyApp extends UiApplication{
    public static void main(String args[]){

        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }
    public MyApp()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new MyScreen());
    } 
}




/*****************
 * MyScreen.java *
 *****************/
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.container.AbsoluteFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;

public class MyScreen extends MainScreen {
    public MyScreen() {
        AbsoluteFieldManager manager = new AbsoluteFieldManager();
        Bitmap img = Bitmap.getBitmapResource("1.png");
        CustomField cf1 = new CustomField(img, "an", "Item");
        CustomField cf2 = new CustomField(img, "another", "Item");
        manager.add(cf1, 10, 10);
        manager.add(cf2, 150, 150);
        //HorizontalFieldManager hfm = new HorizontalFieldManager(
            //  Manager.HORIZONTAL_SCROLL);
        //hfm.add(cf1); hfm.add(cf2);
        //add(hfm);
        add(manager);
    }

}

And the image (1.png) http://www7.pic-upload.de/14.05.11/rhr4jcfuy9f8.png

How can I get the absolute manager to show my custom field?

  • 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-22T03:21:21+00:00Added an answer on May 22, 2026 at 3:21 am

    My guess is that maybe AbsoluteFieldManager is passing 0, 0 to the layout method of your custom field. So your logic in there is calling setExtent(0, 0).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.