0
我通過點擊位於該面板上的按鈕上的事件來更改選項卡面板佈局方面存在問題。主要想法是在每個選項卡面板的小面板上都有自定義菜單(新建,打開,刪除)。當您單擊按鈕時,選項卡面板佈局將更改爲窗體(例如)。我不想使用模態窗口或新窗口,只需通過按鈕單擊將標籤面板佈局(內容)更改爲其他內容。通過該佈局上的子按鈕更改父佈局
我通過點擊位於該面板上的按鈕上的事件來更改選項卡面板佈局方面存在問題。主要想法是在每個選項卡面板的小面板上都有自定義菜單(新建,打開,刪除)。當您單擊按鈕時,選項卡面板佈局將更改爲窗體(例如)。我不想使用模態窗口或新窗口,只需通過按鈕單擊將標籤面板佈局(內容)更改爲其他內容。通過該佈局上的子按鈕更改父佈局
這是錯誤的指定問題 - 你應該問如何通知父組件。 貝婁你有兩個例子展示如何實現你的目標。第一個實現是Jens Janssons在vaadin論壇上提出的建議,將ClickListener作爲構造函數參數傳遞給第二個面板。請注意,爲了能夠從外部面板上移除組件,您需要同時參考外部面板和內部面板。在這個例子中,Kim Lappanen將參考存儲在類變量中。請注意,ther實際上用於您稱爲「面板」的HorizontalLayout,您可以更改它。
public class TestcaseApplication extends Application implements ClickListener {
private static final long serialVersionUID = 75232258896642392L;
private final HorizontalLayout mainLayout = new HorizontalLayout();
private final YourPanel panel = new YourPanel(this);
@Override
public void init() {
setTheme("example");
Window mainWindow = new Window("Playground Application");
setMainWindow(mainWindow);
mainWindow.setContent(mainLayout);
mainLayout.addComponent(panel);
}
public void buttonClick(ClickEvent event) {
mainLayout.removeComponent(panel);
}
public class YourPanel extends Panel {
public YourPanel(ClickListener listener) {
super();
addComponent(new Button("Remove", listener));
}
}
}
另一個例子是直接在內部面板中實現ClickListener。在buttonClick方法中,我只是調用getParent()(返回輸出佈局),然後從佈局中移除它自己。
public class TestcaseApplication extends Application {
private static final long serialVersionUID = 75232258896642392L;
@Override
public void init() {
setTheme("example");
Window mainWindow = new Window("Playground Application");
setMainWindow(mainWindow);
HorizontalLayout mainLayout = new HorizontalLayout();
mainWindow.setContent(mainLayout);
mainLayout.addComponent(new YourPanel());
}
public class YourPanel extends Panel implements ClickListener {
public YourPanel() {
super();
addComponent(new Button("Remove", this));
}
public void buttonClick(ClickEvent event) {
((ComponentContainer) getParent()).removeComponent(this);
}
}
}