简体   繁体   English

如何在vaadin中向右推我的按钮?

[英]How to push my buttons to the right in vaadin?

So I know I could do this with css, but I'm trying not to write any css outside of what ships with the theme, because I'm prototyping. 所以我知道我可以使用CSS做到这一点,但是我正在尝试不编写带有主题的东西之外的任何CSS,因为我正在制作原型。

@SpringComponent
@Scope( ConfigurableBeanFactory.SCOPE_PROTOTYPE )
class CharacterEditDialog extends VerticalLayout {


private static final long serialVersionUID = -2755765492408272282L;
private final transient CrudRepository<Character, Long> repository;

private final TextField name = new TextField();
private final TextField concept = new TextField();
private final TextField apparentAge = new TextField();
private final RichTextArea description = new RichTextArea();
private final RichTextArea biography = new RichTextArea();
private final RichTextArea appearance = new RichTextArea();

private final Button save = new Button( FontAwesome.SAVE );
private final Button cancel = new Button();
private final Button delete = new Button( FontAwesome.TRASH_O );
private final HorizontalLayout actions = new HorizontalLayout( save, cancel, delete );

@Autowired
CharacterEditDialog( final CrudRepository<Character, Long> repository ) {
    this.repository = repository;
    this.setMargin( true );
    this.setSpacing( true );
    this.save.setStyleName( ValoTheme.BUTTON_PRIMARY );
    this.save.setClickShortcut( ShortcutAction.KeyCode.ENTER );

    this.description.setWidth( 100, Unit.PERCENTAGE );
    this.biography.setWidth( 100, Unit.PERCENTAGE );
    this.appearance.setWidth( 100, Unit.PERCENTAGE );
}

Component edit( final Character entity ) {
    BeanFieldGroup.bindFieldsUnbuffered( entity, this );

    this.save.addClickListener( ComponentUtils.runAndCloseWindow( () -> repository.save( entity ) ) );
    this.delete.addClickListener( ComponentUtils.runAndCloseWindow( () -> repository.delete( entity ) ) );
    return this;
}

@PostConstruct
void init() {
    FormLayout layout = new FormLayout(  );
    layout.addComponent( createTopRow() );
    layout.addComponents( appearance, description, biography );

    HorizontalLayout actionBarWrapper = new HorizontalLayout( actions );
    actionBarWrapper.setWidth( 100, Unit.PERCENTAGE );
    actionBarWrapper.setDefaultComponentAlignment( Alignment.MIDDLE_RIGHT );

    this.addComponents( actionBarWrapper, layout );
}

Component createTopRow() {
    HorizontalLayout topRow = new HorizontalLayout( name, concept, apparentAge );
    topRow.setDefaultComponentAlignment( Alignment.MIDDLE_RIGHT );
    topRow.setSpacing( true );
    topRow.setWidth( 100, Unit.PERCENTAGE );
    return topRow;
}

}

I want all of the buttons in the action bar to be right aligned in the layout. 我希望action栏中的所有按钮在布局中都正确对齐。 When looking at the dom I can see that the actionBarWrapper is full width, and the components are grouped together, but the alignment doesn't seem to be doing its job 当查看dom时,我可以看到actionBarWrapper是全角的,并且组件被组合在一起,但是对齐似乎并没有完成

A solution is to add a spacer before first element. 一种解决方案是在第一个元素之前添加一个间隔符。

Component createTopRow() {
    Label spacer = new Label();
    spacer.setWidthUndefined();
    HorizontalLayout topRow = new HorizontalLayout( spacer, name, concept, apparentAge );
    topRow.setExpandRatio(spacer, 1);
    topRow.setSpacing( true );
    topRow.setWidth( 100, Unit.PERCENTAGE );
    return topRow;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM