Home >Java >javaTutorial >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:
<code class="language-xml"><dependency> <groupId>io.github.hugoquinn2</groupId> <artifactId>fxpopup</artifactId> <version>1.1.0</version> </dependency></code>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
<code class="language-java">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); }</code>
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:
<code class="language-java">public class ThumbnailImage extends ImageView { // ... (代码与原文相同) ... }</code>
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!