前提・実現したいこと
解答のボタンを何度も押しても、ボタンが消えないようにしたいです。
発生している問題・エラーメッセージ
解答のボタンを1回押したときに、TextAreaに出力した後にボタン全てが消えてしまいます。
該当のソースコード
Java
1package application; 2 3import javafx.application.Application; 4import javafx.collections.FXCollections; 5import javafx.scene.Scene; 6import javafx.scene.control.Button; 7import javafx.scene.control.ComboBox; 8import javafx.scene.layout.BorderPane; 9import javafx.scene.layout.HBox; 10import javafx.scene.text.Text; 11import javafx.stage.Stage; 12 13 14public class Main extends Application { 15 16 @Override 17 public void start(Stage primaryStage) { 18 try { 19 20 primaryStage.setWidth(300); 21 primaryStage.setHeight(330); 22 23 24 String[] color = {"1","2","3","4","5","6","7","8","9"}; 25 ComboBox<String> button1 = new ComboBox<String>(FXCollections.observableArrayList(color)); 26 button1.setPrefSize(60, 1); 27 button1.getSelectionModel().selectFirst(); 28 29 String[] color2 = {"2","2","3","4","5","6","7","8","9"}; 30 ComboBox<String> button2 = new ComboBox<String>(FXCollections.observableArrayList(color2)); 31 button2.setPrefSize(60, 1); 32 button2.getSelectionModel().selectFirst(); 33 34 String[] color3 = {"3","2","3","4","5","6","7","8","9"}; 35 ComboBox<String> button3 = new ComboBox<String>(FXCollections.observableArrayList(color3)); 36 button3.setPrefSize(60, 1); 37 button3.getSelectionModel().selectFirst(); 38 39 String[] color4 = {"4","2","3","4","5","6","7","8","9"}; 40 ComboBox<String> button4 = new ComboBox<String>(FXCollections.observableArrayList(color4)); 41 button4.setPrefSize(60, 1); 42 button4.getSelectionModel().selectFirst(); 43 44 Button kaitou = new Button("解答"); 45 kaitou.setPrefSize(60, 1); 46 47 kaitou.setOnAction(event -> { 48 49 Text t = new Text(); 50 t.setText("a"); 51 BorderPane root = new BorderPane(); 52 root.setLeft(t); 53 primaryStage.setScene(new Scene(root)); 54 primaryStage.show(); 55 56 57 }); 58 59 60 61 HBox box = new HBox(); 62 63 box.getChildren().addAll(button1,button2,button3,button4,kaitou); 64 65 BorderPane root = new BorderPane(); 66 root.setBottom(box); 67 primaryStage.setScene(new Scene(root)); 68 primaryStage.show(); 69 } catch (Exception e) { 70 e.printStackTrace(); 71 } 72 } 73 74 public static void main(String[] args) { 75 launch(args); 76 } 77} 78
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。