簡體   English   中英

如何在Vaadin中顯示表格?

[英]How do I display a table in Vaadin?

Vaadin 7項目中有兩個課程。 我很難在主UI類中顯示表。 MyTable.java和DocUI.java。 加載localhost:8080時,如何在DocUI.java中顯示/顯示表?

public class MyTable extends DocUI{

public MyTable() {

    Table table = new Table("The Brightest Stars");

    table.addContainerProperty("Name", String.class, null);
    table.addContainerProperty("Mag", Float.class, null);

    Object newItemId = table.addItem();
    Item row1 = table.getItem(newItemId);
    row1.getItemProperty("Name").setValue("Sirius");
    row1.getItemProperty("Mag").setValue(-1.46f);

    table.addItem(new Object[] {"Canopus", -0.72f}, 2);
    table.addItem(new Object[] {"Arcturus", -0.04f}, 3);
    table.addItem(new Object[] {"Alpha Centauri", -0.04f}, 4);

    table.setPageLength(table.size());
    }
}



public class DocUI extends UI {

// new addition 4/28
public String[] userString = { "jacob.smith@example.com",
        "isabella.johnson@example.com", "ethan.williams@example.com",
        "emma.jones@example.com", "michael.brown@example.com" };

// create combo box
public ComboBox comboBox1 = new ComboBox("Random Combo Box") {

};

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = DocUI.class)
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {

    final VerticalLayout layout = new VerticalLayout();

    layout.setMargin(true);

    setContent(layout);

    Button button = new Button("Click Me");
    Button button2 = new Button("I am button 2");

    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            layout.addComponent(new Label("Thank you for clicking"));
        }
    });

    @SuppressWarnings("deprecation")
    FieldGroup form = new FieldGroup();
    layout.setSizeFull();
    layout.addComponent(button);
    layout.addComponent(button2);
    addComponent(MyTable.table);


    //new addition 4/28

    layout.addComponent(comboBox1);     
    comboBox1.setInputPrompt("Select a value");         
    comboBox1.addItems("--add new user--", "jacob.smith@example.com", "isabella.johnson@example.com","ethan.williams@example.com","emma.jones@example.com","michael.brown@example.com");

}
}

你知道Java嗎? 不要從MyTable中的UI擴展。

public class MyTable{

private Table table;

  public MyTable() {

    this.table = new Table("The Brightest Stars");
    /* do something with table */
  }

 public function getTable() {
   return this.table;
 }
}

知道您可以創建一個MyTable對象,然后將其用於getTable並將其添加到布局中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM