Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Button alignment problem

    I have a simple window running but am unable to right-align the buttons. No matter what I do, they align to the left. Here's my code:

    Code:
            // Create and format the window.
            final Window winSystem = new Window();
            winSystem.setWidth(300);
            winSystem.setHeight(200);
            winSystem.setShowMinimizeButton(false);
            winSystem.setIsModal(true);
            winSystem.setShowModalMask(true);
            winSystem.centerInPage();
    
            // Create the form to go on the window.
            final DynamicForm form = new DynamicForm();
            form.setHeight100();
            form.setWidth100();
            form.setPadding(5);
            form.setLayoutAlign(VerticalAlignment.BOTTOM);
            form.setDataSource(SystemListGridDataSource.getInstance());
    
            // Add the text items for the form.
            TextItem textName = new TextItem("Name");
            textName.setTitle("Name");
            textName.setSelectOnFocus(true);
            textName.setWrapTitle(false);
            textName.setLength(128);
    
    
            TextItem textComment = new TextItem("Comment");
            textComment.setTitle("Comment");
            textComment.setSelectOnFocus(true);
            textComment.setWrapTitle(false);
            textComment.setLength(128);
    
            // Add all the fields to the form.
            form.setFields(textName,
                           textComment);
    
    
            // Create a layout and add the form to it.
            VLayout vLayout = new VLayout();
            vLayout.setAlign(Alignment.RIGHT);
            vLayout.addMember(form);
    
            // Create the cancel button.
            Button buttonCancel = new Button("Cancel");
            buttonCancel.setLayoutAlign(Alignment.RIGHT);
            buttonCancel.addClickHandler(new ClickHandler()
            {
                public void onClick(ClickEvent event)
                {
                    winSystem.destroy();
                }
            });
    
            // Create the OK button.
            Button buttonOK = new Button("OK");
            buttonOK.setLayoutAlign(Alignment.RIGHT);
            buttonOK.addClickHandler(new ClickHandler()
            {
                public void onClick(ClickEvent event)
                {
                    if (form.validate())
                    {
                        form.saveData();
                        winSystem.destroy();
                    }
                }
            });
    
            // Create a layout to hold the buttons.
            HLayout buttonLayout = new HLayout();
            buttonLayout.setLayoutAlign(Alignment.RIGHT);
            buttonLayout.addMember(buttonOK);
            buttonLayout.addMember(buttonCancel);
    
            // Add the button layout to the layout and then add the layout to the
            // window.
            vLayout.addMember(buttonLayout);
            winSystem.addItem(vLayout);
            winSystem.show();
    Any suggestions?

    #2
    Use the Watch Tab in the Developer Console. The buttonLayout is as wide as the Window so it doesn't matter what it's layoutAlign setting is.

    Any one of the following 3 approaches would fix it.
    1. setAlign(RIGHT) on the buttonLayout so it's members align right
    2. set buttonLayout's width smaller so layoutAlign can have an effect
    3. add a LayoutSpacer before the buttons

    Comment

    Working...
    X