Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. public class RowListCell extends ListCell<Model> {
  2. private ObservableList<Model> rows = FXCollections.observableArrayList();
  3. CreateSchemeView csv = new CreateSchemeView(null);
  4. private HBox content = new HBox();
  5. private TextField tf0 = new TextField();
  6. private TextField tf1 = new TextField();
  7. private TextField tf2 = new TextField();
  8. private TextField tf3 = new TextField();
  9. private Button add = new Button("+");
  10. private Button sub = new Button("-");
  11. Model model = new Model(tf0, tf1, tf2, tf3);
  12.  
  13. public RowListCell() {
  14.  
  15.  
  16. content.getChildren().addAll(tf0, tf1, tf2, tf3, add, sub);
  17. content.setSpacing(10);
  18. setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
  19. setGraphic(content);
  20. }
  21.  
  22. protected void updateItem(model.Model item, boolean empty) {
  23. super.updateItem(item, empty);
  24. if (item == null || empty) {
  25. setText(null);
  26. setGraphic(null);
  27. } else {
  28. setGraphic(content);
  29.  
  30. add.setOnAction(e -> {
  31. Model newRow = new Model(tf0, tf1, tf2, tf3);
  32. rows.add(newRow);
  33. });
  34. sub.setOnAction(e -> {
  35. rows.remove(item);
  36. });
  37. }
  38. }
  39.  
  40. public class CreateSchemeView extends VBox {
  41. Model model = new Model();
  42. private final Button view = new Button("Zurück");
  43.  
  44. private ObservableList<Model> rows = FXCollections.observableArrayList();
  45. public ListView<Model> list = new ListView<>();
  46. StackPane root = new StackPane();
  47. Pane pane = new Pane();
  48. VBox vbox = new VBox();
  49. HBox hbox = new HBox();
  50. Button save = new Button("Speichern");
  51.  
  52. public CreateSchemeView(final CreateSchemeController createSchemeController) {
  53. initCreateScheme();
  54.  
  55. view.setOnAction(event -> {
  56. System.out.println("ButtonB has been pressed, switching to ViewA.");
  57.  
  58.  
  59. final Stage primaryStage = createSchemeController.getPrimaryStage();
  60. final ViewController viewController = new ViewController(primaryStage);
  61. final Scene scene = new Scene(viewController.getView(),250,600);
  62. scene.getStylesheets().add("style.css");
  63. primaryStage.setScene(scene);
  64.  
  65. });
  66.  
  67. }
  68.  
  69. public void initCreateScheme(){
  70. vbox.setLayoutX(0);
  71. vbox.setLayoutY(0);
  72. vbox.setMaxWidth(200);
  73. vbox.setMaxHeight(800);
  74.  
  75. hbox.setLayoutX(205);
  76.  
  77. rows.add(model);
  78.  
  79. list.setCellFactory(c -> new RowListCell());
  80. list.setItems(rows);
  81.  
  82. vbox.getChildren().addAll(view, save);
  83. vbox.setPadding(new Insets(10,10,10,10));
  84. vbox.setSpacing(5);
  85. root.setLayoutX(205);
  86. root.setLayoutY(10);
  87. root.setPrefWidth(900);
  88. root.setPrefHeight(580);
  89. root.getChildren().addAll(list);
  90.  
  91. hbox.getChildren().addAll(root);
  92. hbox.setLayoutY(10);
  93. pane.getChildren().addAll(vbox, hbox);
  94.  
  95. this.getChildren().addAll(pane);
  96. }
  97.  
  98. public Button getCreateSchemeView() {
  99. return view;
  100. }
  101.  
  102. public class Model {
  103.  
  104.  
  105. private TextField tf0;
  106. private TextField tf1;
  107. private TextField tf2;
  108. private TextField tf3;
  109.  
  110. public Model(TextField tf0, TextField tf1, TextField tf2, TextField tf3) {
  111.  
  112.  
  113. this.tf0 = tf0;
  114. this.tf1 = tf1;
  115. this.tf2 = tf2;
  116. this.tf3 = tf3;
  117.  
  118. }
  119.  
  120. public Model() {}
  121.  
  122.  
  123. public TextField getTF0() {
  124. return tf0;
  125. }
  126.  
  127. public void setTF0(TextField tf0) {
  128. this.tf0 = tf0;
  129. }
  130.  
  131. public TextField getTF1() {
  132. return tf1;
  133. }
  134.  
  135. public void setTF1(TextField tf1) {
  136. this.tf1 = tf1;
  137. }
  138.  
  139. public TextField getTF2() {
  140. return tf2;
  141. }
  142.  
  143. public void setTF2(TextField tf2) {
  144. this.tf2 = tf2;
  145. }
  146.  
  147. public TextField getTF3() {
  148. return tf3;
  149. }
  150.  
  151. public void setTF3(TextField tf3) {
  152. this.tf3 = tf3;
  153. }
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement