Home > Java > javaTutorial > How make Thumbnails on JavaFX?

How make Thumbnails on JavaFX?

Susan Sarandon
Release: 2025-01-28 04:19:12
Original
419 people have browsed it

How make Thumbnails on JavaFX?

This article introduces how to create a clicked interactive shrinkage map in the Javafx desktop application. After clicking the shrinkage diagram, larger images will be displayed, and a superposition layer with outstanding display images and its details. Similar to interactive examples of shrinking diagrams in W3SCHool.

First of all, you need to add the FXPopup library dependence:

<dependency>
    <groupId>io.github.hugoquinn2</groupId>
    <artifactId>fxpopup</artifactId>
    <version>1.1.0</version>
</dependency>
Copy after login
<建> Create a simple thumbnail

A simple retractable diagram only requires a superposition layer and a image. The following example shows how to create a thumbnail:

<建> Create custom ImageView for shrinking diagrams
Rectangle overlay;
FxPopup fxPopup;
ImageView imageView;

@FXML
public void initialize() {
    fxPopup = new FxPopup();
    imageView = new ImageView("https://th.bing.com/th/id/OIP.TnnO-9C6THhBBCzOhTe7mQHaFj?rs=1&pid=ImgDetMain");
    overlay = new Rectangle();
    overlay.setFill(Color.BLACK);
    overlay.setOpacity(0.3);
    overlay.setOnMouseClicked(event -> {
        MasterUtils.remove(imageView);
        MasterUtils.remove(overlay);
    });
}

@FXML
protected void onThumbnails() {
    fxPopup.show(overlay, Pos.CENTER);
    overlay.widthProperty().bind(((Pane) MasterUtils.getRoot()).widthProperty());
    overlay.heightProperty().bind(((Pane) MasterUtils.getRoot()).heightProperty());
    fxPopup.show(imageView, Pos.CENTER);
}
Copy after login

In order to facilitate the creation of a narrow diagram, we create a custom class to inherit the

and make it come with its own contraction diagram display function:

ThumbnailImage ImageView Using custom <使用> class, you can easily create multiple shrinkage map objects and add to any location:

public class ThumbnailImage extends ImageView {
    // ... (代码与原文相同) ...
}
Copy after login

Through the above steps, you can easily create and use interactive retractable diagrams in the Javafx application. Please note that the ThumbnailImage class and methods need to be adjusted according to the actual project.

The above is the detailed content of How make Thumbnails on JavaFX?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template