Button 如何在javafx中从UI视图中删除按钮的实例
我在java fx中有一个按钮,它出现在UI的HBox中,我想在单击同一个按钮时删除该按钮。我已经为同一个按钮编写了操作事件:Button 如何在javafx中从UI视图中删除按钮的实例,button,javafx,Button,Javafx,我在java fx中有一个按钮,它出现在UI的HBox中,我想在单击同一个按钮时删除该按钮。我已经为同一个按钮编写了操作事件: @FXML private HBOx projectlist; String buttonid; 字符串按钮名; /** *初始化控制器类。 */ @FXML 公共按钮删除 button.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public
@FXML
private HBOx projectlist;
String buttonid;
字符串按钮名;
/**
*初始化控制器类。
*/
@FXML
公共按钮删除
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
buttonid= button.getId();
buttoname = button.getText();
projectlist.getChildren().remove(buttoname);
}
});
试一试
button.setOnMouseClicked(新建EventHandler()){
@凌驾
公共无效句柄(MouseEvent t){
buttonid=button.getId();
ButtonName=button.getText();
projectList.getChildren().remove(按钮);
}
});
很抱歉,我不理解这些编辑。你能修改格式并使它更清晰吗?只需调用projectList.getChildren().remove(按钮)按钮的处理程序方法中的代码>。(顺便说一句,你真的应该使用setOnAction
,而不是setOnMouseClicked
)谢谢詹姆斯……事实上我找到了解决方案……可能不是最好的方法,但对我来说仍然有效。。。。。。。。。
projectlist.setSpacing(10);
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
buttonid= button.getId();
buttoname = button.getText();
}
});
} @FXML
private void gotoDelete(ActionEvent event) throws IOException{
ProjectModule.DeleteProject(Integer.parseInt(buttonid));
projectlist.getChildren().remove(button);
}
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
buttonid= button.getId();
buttoname = button.getText();
projectList.getChildren().remove(button);
}
});