问题描述
我已经创建了一个程序,其中我创建了一个 TabPane ,其中有多个标签。
当有人试图关闭任何Tab时,我想这样做,然后我想执行我自己的代码。即当用户单击任何Tab的默认关闭按钮时,它将要求确认。如果用户说是,那么标签将被关闭,否则它将保持打开状态。
我该怎么做?
我正在做如下的事情。但仍然正在关闭。我如何使用该标签?
Tab tab = new Tab();
TabPane tabPane = new TabPane();
tabPane.getTabs()。add(tab);
tab.setOnClosed(new EventHandler< Event>(){
@Override
public void handle(Event t){
t.consume();
}
});
我正在得到我自己的方式如下: br />我创建了一个超链接,并将其设置为该Tab的图形,其工作正常。
Hyperlink hlink =新的Hyperlink();
Image image = new Image(MyClass.class.getResourceAsStream(/ images / close.png));
hlink.setGraphic(new ImageView(image));
hlink.setFocusTraversable(false);
Tab tab = new Tab();
tab.setGraphic(hlink);
hlink.setOnAction(new EventHandler< ActionEvent>(){
@Override
public void handle(ActionEvent e){
// Do somthing
}
});
I have create a program in which I have create a TabPane,in which there are multiple Tabs.I want to do that when Someone trying to close any Tab, Then I want to execute my own code. i.e when user click on default close button for any Tab, then it will ask for confirmation. If user say "Yes" then tab will be closed otherwise it will remain open.
How can I do this?
I am doing something like below. but still is getting closed. How would I consume that Tab?
Tab tab = new Tab();
TabPane tabPane=new TabPane();
tabPane.getTabs().add(tab);
tab.setOnClosed(new EventHandler<Event>() {
@Override
public void handle(Event t) {
t.consume();
}
});
I am getting my own way as given below.
I have created a hyperlink and set it as graphic for that Tab and its work fine for me.
Hyperlink hlink = new Hyperlink();
Image image = new Image(MyClass.class.getResourceAsStream("/images/close.png"));
hlink.setGraphic(new ImageView(image));
hlink.setFocusTraversable(false);
Tab tab = new Tab();
tab.setGraphic(hlink);
hlink.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
//Do somthing
}
});
这篇关于TabPane中的Tab在默认关闭时消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!