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>
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); }
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 { // ... (代码与原文相同) ... }
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!