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
| import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
/**
*
* @author
*/
public class TestModality extends Application {
@Override
public void start(Stage stage) throws Exception {
VBox root = new VBox();
Image image = new Image(getClass().getResource("cross.png").toExternalForm());
ImageView imageView = new ImageView(image);
imageView.setOnMouseClicked((MouseEvent event) -> {
if (event.getButton().equals(MouseButton.PRIMARY)) {
showDialog();
}
});
root.getChildren().add(imageView);
Scene scene = new Scene(root, 300, 200);
stage.setScene(scene);
stage.setTitle("The Primary Stage");
stage.show();
}
private void showDialog() {
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
Label modalityLabel = new Label("Bonjour tout le monde...!");
Button closeButton = new Button("Close");
closeButton.setOnAction(e -> stage.close());
VBox root = new VBox();
root.getChildren().addAll(modalityLabel, closeButton);
Scene scene = new Scene(root, 200, 100);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
} |
Partager