我有下一個問題。我想創建帶有標題(位於頁面頂部)和菜單(位於頁面中心)的頁面。有我的代碼:Vaadin在佈局中的組件位置
package org.crabar.views;
import com.vaadin.annotations.Theme;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.*;
import org.crabar.ViewController;
/**
* Created by Crabar on 01.11.2014.
*/
@Theme("mytheme")
public class StartView extends VerticalLayout implements View {
public StartView() {
setSizeFull();
setMargin(true);
createTitle();
createMenu();
}
private void createMenu() {
VerticalLayout menu = new VerticalLayout();
menu.setSpacing(true);
menu.setWidth(150, Unit.PIXELS);
menu.setHeightUndefined();
addComponent(menu);
setComponentAlignment(menu, Alignment.MIDDLE_CENTER);
Button startGameButton = new Button("Start game", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
ViewController.getInstance().changeView(ViewController.GAME_VIEW);
}
});
startGameButton.setWidth(100, Unit.PERCENTAGE);
menu.addComponent(startGameButton);
Button achievementsButton = new Button("Achievements", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
//
}
});
achievementsButton.setEnabled(false);
achievementsButton.setDescription("The achievements will be soon...");
achievementsButton.setWidth(100, Unit.PERCENTAGE);
menu.addComponent(achievementsButton);
}
private void createTitle() {
Label label = new Label("Craberoid 2.0");
label.setStyleName("title-style");
addComponent(label);
label.setWidth(null);
label.setHeight(null);
setComponentAlignment(label, Alignment.TOP_CENTER);
}
}
除了菜單在屏幕上的位置以外的所有罰款。它看起來未來:
所以它不是在屏幕的中心,但中心和底部之間。我花了幾個小時,但沒有找到如何設置中心的菜單和頂部的標題。
This Works!謝謝。不知道expandRatio ... – Crabar 2014-11-03 19:39:02