1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| package gridpane.remove;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.util.Arrays;
public final class Main extends Application {
public void addToGridPane(final Label nomArticle, final Label prixArticle) {
nomArticle.setStyle("-fx-border-color: green; -fx-border-width: 0.5;");
prixArticle.setStyle("-fx-border-color: orange; -fx-border-width: 0.5;");
final var gridPane = new GridPane();
gridPane.setStyle("-fx-border-color: red; -fx-border-width: 0.5; -fx-padding: 5px; -fx-grid-lines-visible: true;");
gridPane.setId(nomArticle.getText() + "+" + prixArticle.getText());
gridPane.setMinWidth(200);
gridPane.setMaxWidth(200);
final var col1 = new ColumnConstraints();
col1.setPercentWidth(75);
final var col2 = new ColumnConstraints();
col2.setPercentWidth(25);
gridPane.getColumnConstraints().setAll(col1, col2);
gridPane.getRowConstraints().setAll(new RowConstraints());
GridPane.setConstraints(nomArticle, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER);
GridPane.setConstraints(prixArticle, 1, 0, 1, 1, HPos.CENTER, VPos.CENTER);
gridPane.getChildren().setAll(nomArticle, prixArticle);
VBox.setVgrow(gridPane, Priority.NEVER);
gridPane.setOnMouseClicked(event -> {
System.out.println(gridPane.getId());
anchorPaneCommande.getChildren().remove(gridPane);
});
anchorPaneCommande.getChildren().add(gridPane);
}
private VBox anchorPaneCommande = new VBox();
@Override
public void start(final Stage stage) throws Exception {
anchorPaneCommande.setStyle("-fx-border-color: blue; -fx-border-width: 0.5; -fx-gap: 40px");
anchorPaneCommande.setFillWidth(true);
final var toTest = new String[][]{
new String[]{"Blabla", "BlablaBlabla"},
new String[]{"Bleble", "BlebleBleble"},
new String[]{"Blibli", "BlibliBlibli"},
new String[]{"Bloblo", "BlobloBloblo"},
new String[]{"Blublu", "BlubluBlublu"},
new String[]{"Blybly", "BlyblyBlybly"}
};
Arrays.stream(toTest)
.forEach(tuple -> addToGridPane(new Label(tuple[0]), new Label(tuple[1])));
final var scene = new Scene(anchorPaneCommande);
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
} |
Partager