开发者

setting the position of a button in blackberry java

how t开发者_StackOverflow社区o set the position of a button in java blackberry.


You can position a button or any other component on a screen by creating a Manager class and overriding the sublayout() method. A Manager is kind of like a Panel in java i.e an area of the screen you can add components to. In the sublayout() method you should

  1. set the size of the component with layoutChild()

  2. set the position of the component with setPositionChild()

  3. Set the overall size of the Manager with setExtent()

something like

    button = new ButtonField();

    HorizontalFieldManager manager = new HorizontalFieldManager(){
        protected void sublayout(int width, int height) {
            int buttonWidth = button.getPreferredWidth();
            int buttonHeight = button.getPreferredHeight();
            layoutChild(button,buttonWidth, buttonHeight);
            setPositionChild(button, 0, 0);
            setExtent(width, height);
        }
    };
    manager.add(button);

You can override getPreferredWidth() and getPreferredHeight() for your button if you want to specify a certain width and height.

See

Custom layout Manager

Manager class

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜