i have a TabPane
and Button
once on click on this button should add a new Tab to the TabPane like: Tab1
for the second time on click on the button should add another tab to the TabPane like: Tab2
. So while clicking on this button should add 1
to the text of the Tab in every time. this is my code:
butser.setOnAction( new EventHandler<ActionEvent>() {
@Override
public void handle( ActionEvent event )
{
int hu = 0 ;
Tab tab = new Tab( "Tab" + hu);
tabs.getTabs().add( tab );
}
} );
How i can do that in javafx and thank you soooo much :)
Try this
private int lastNumber = 0;
@Override
public void start( Stage stage )
{
TabPane tabPane = new TabPane();
Button b = new Button( "add" );
b.setOnAction( new EventHandler<ActionEvent>()
{
@Override
public void handle( ActionEvent event )
{
Tab tab = new Tab( "Tab" + lastNumber );
tabPane.getTabs().add( tab );
lastNumber++;
}
} );
Scene scene = new Scene( new VBox( b, tabPane ), 200, 100 );
stage.setScene( scene );
stage.show();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.