Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

user interface - Blackberry - Setting LabelField background color

I want to place several LabelFields with right-aligned text on a MainScreen with an alice blue background. Unfortunately I can't seem to figure out how to make that happen.

The best I can do is set my backround to Color.ALICEBLUE on a MainScreen and place LabelFields on the screen (also with a alice blue background).

    public void paint(Graphics graphics) {
        graphics.setBackgroundColor(Color.ALICEBLUE);
        graphics.clear();
        super.paint(graphics);  
    }

and...

    LabelField display = new LabelField("", LabelField.FIELD_RIGHT){
        public void paint(Graphics graphics) {
            graphics.setColor(Color.DIMGRAY);
            graphics.setBackgroundColor(Color.ALICEBLUE);
            graphics.clear();
            super.paint(graphics);  
        }
    };

Overriding the MainScreen paint routine gives me my alice blue background, but overriding the LabelFields' paint routines does not seem to be adequate. The result is a white row, with a alice blue background behind the label text only. Adding USE_ALL_WIDTH corrects the background issue, but I can't right align with USE_ALL_WIDTH.

Does anyone know a work around for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In versions <= 4.5 you can create VerticalFieldManager with overrided paint():

class BGManager extends VerticalFieldManager {
    public BGManager() {
        super(USE_ALL_HEIGHT|USE_ALL_WIDTH);
    }
    public void paint(Graphics graphics)
    {
        graphics.setBackgroundColor(Color.DARKRED);
        graphics.clear();
        super.paint(graphics);
    }
}

Then use it on youre screen adding simple LabelField to it:

class Scr extends MainScreen {
    BGManager manager = new BGManager();
    public Scr() {
        super();
        add(manager);       
        manager.add(new LabelField("Hello!", FIELD_RIGHT));
        manager.add(new LabelField("This is a test", FIELD_RIGHT));
    }
}

In versions >= 4.6 you can use setBackgroud() method for default screen manager:

class Scr extends MainScreen {  
    public Scr() {
        super();
        VerticalFieldManager manager = 
            (VerticalFieldManager)getMainManager();
        manager.setBackground(
            BackgroundFactory.createSolidBackground(
                Color.DARKRED));        
        manager.add(new LabelField("Hello!", FIELD_RIGHT));
        manager.add(new LabelField("This is a test", FIELD_RIGHT));
    }
}

See BB KB DB-00131 - How to - Change the background color of a screen


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...