I'm new to JavaFX, so please forgive the noobishness.
So I'm making a Picture Viewer. This is my first time designing a GUI with the MVC paradigm, so I'm not very sure what I'm doing.
What I'm Trying To Accomplish:
It's just a normal picture viewer. Like your standard Windows program that opens when you want to look at a picture.
When you reszie the Picture Viewer window, the image automatically fits either with width or with height of the Image. If there is any amount of zoom - it becomes a viewfinder.
What I Did:
I'm using ScenBuilder to design my views. I currently have 2 views:
the Root.fxml view, which is a
BorderPane
with just aMenuBar
on top with aMenuItem
"Open" that triggers aFileChooser
and sets the MainApp.javacurrentImage
Image
property to whatever the user chose.Nested inside of (
root.setCenter
) it I have ImageViewer.fxml view, which is anAnchorPane
that only contains anImageView
.
Unfortunately, the AnchorPane
+ImageView
combination can't achieve the effect I'm trying to achieve.
Fortunately, over here I found a custom ImageViewPane
class that does exactly what I want: resizes the Pane based on the window size. So I want to use it insead of the AnchorPane
. (Here's ImageViewPane.java)
The problem is that SceneBuilder accepts only FXML for custom classes, and I have no idea how to go about converting it. What do I need to do?
Current ImageViewer.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="JImageViewer.view.ImageViewerController">
<children>
<ImageView fx:id="imageView" layoutX="107.0" layoutY="90.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>