我有一个TabPane
,Button
一旦单击此按钮,应向TabPane添加一个新的选项卡,如:Tab1
第二次单击该按钮应向TabPane添加另一个选项卡,如:Tab2
。因此,在单击此按钮时1
,每次都应将其添加到选项卡的文本中。这是我的代码:
butser.setOnAction( new EventHandler<ActionEvent>() {
@Override
public void handle( ActionEvent event )
{
int hu = 0 ;
Tab tab = new Tab( "Tab" + hu);
tabs.getTabs().add( tab );
}
} );
我如何在javafx中做到这一点,非常感谢:)
尝试这个
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();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句