root.getChildren().remove(btn);root => Type is StackPane
btn => your button name
Example:
package fxtext;Reference:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
* @author terrapinssky
*/
public class FxText extends Application {
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
Button btn = new Button("Button");
root.getChildren().add(btn);
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
root.getChildren().remove(btn);
}
});
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
https://community.oracle.com/thread/2369785?start=0&tstart=0
No comments :
Post a Comment