【发布时间】:2020-03-11 16:27:44
【问题描述】:
我有一个 JavaFX GUI,它根据团队的数量创建和添加许多按钮,这些按钮存储在一个 ArrayList 中,这个数字会有所不同。
每个团队都有一份人员名单。
我的问题是我想编写某种逻辑,在不知道我可以添加按钮列表的情况下添加按钮列表,然后单击每个按钮将显示其不同的花名册。
Button getTeamsButton = new Button( "Load Teams and Details" );
getTeamsButton.setOnAction( e -> {
getTeams.scrapeTeams();
if( !getTeams.getTeams().isEmpty() )
{
for( int i = 0; i < getTeams.getTeams().size(); i++ )
{
Button teamName = new Button( getTeams.getTeams().get(i).getTeamName() );
teamNamesButtons.add( teamName );
layout1.getChildren().add( teamNamesButtons.get( i ) );
}
我能够创建按钮。
getTeamsButton.setDisable( true );
teamNamesButtons.get( 0 ).setOnAction( f -> {
for(int i = 0; i < getTeams.getTeams().get( 0 ).getRoster().size(); i++) {
System.out.println(getTeams.getTeams().get( 0 ).getRoster().get( i ));
}
});
}
} );
如果我指定列表中的哪个项目可以打印名册,我如何解释顶部按钮的逻辑是团队 0,第二个是团队 1,等等?
任何建议将不胜感激?
【问题讨论】:
标签: java button javafx arraylist