gpt4 book ai didi

java - 如何在 Vaadin 中显示表格?

转载 作者:行者123 更新时间:2023-12-01 09:58:20 26 4
gpt4 key购买 nike

我的 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-Object,然后使用它来获取Table并将其添加到布局中。

关于java - 如何在 Vaadin 中显示表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37013527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com