When I am trying to align fields vertically, they aren't behaving what I expected?(Blackberry JDE4.5.0 eclipse)

橙三吉。 提交于 2020-01-02 18:05:32

问题


I am using Eclipse & JDE 4.5.0 plug-in. How to align fields vertically. Can we align fields like LEFT_BOTTOM,RIGHT_BOTTOM, LEFT_VCENTER, RIGHT_VCENTER, CENTER(vertically & horizontally), BOTTOM_CENTER, etc...?


回答1:


BlackBerry UI field managers are notoriously annoying when dealing with field alignment. Managers seem to ignore all style flags (like HCENTER, VCENTER, etc) so the only way you'll be able to do this is to override the sublayout method of your manager and do it yourself.

Here's a little snippet to show you what I mean. This particular code actually does horizontal centering, not vertical centering, but once you get the idea you can implement any styles you need.

VerticalFieldManager    mainmanager     = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT)
{
    protected void sublayout( int width, int height ) {

        super.sublayout( width, height );

        width = getWidth();
        height = getHeight();

        for (int i = 0;i < this.getFieldCount() - 1; i++)
        {
            Field field = this.getField(i);
            //this positions the item in the middle of the manager
            int x = (int)((width - field.getWidth()) * 0.50);
            setPositionChild(field, x, field.getTop());
        }
    }

Please note that the USE_ALL_WIDTH and USE_ALL_HEIGHT style flags are important. If you want to do things like vertical centering, bottom-right aligning, etc. you will need to write the positioning code yourself. For bottom-right alignment for example you could set the x position to the width of the manager minus the width of the field, and the y position to the height of the manager minus the height of the field.

If you want to be able to use one custom manager class to handle multiple different styles (like bottom right, bottom left) you can add some logic in sublayout to check the field's style flag and then position the field appropriately.

Hopefully this all makes sense and helps you. :)




回答2:


HorizontalFieldManager only accepts Vertical Alignment Styles and VerticalFieldManager only accept Horizontal Alignment. That's it. Annoying ++



来源:https://stackoverflow.com/questions/1365923/when-i-am-trying-to-align-fields-vertically-they-arent-behaving-what-i-expecte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!