Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ImageView within a ScrollPane does not react on ScrollPane positioning

1058154Dec 3 2013

Hi

I have a problem with an ImageView positioned within a ScrollPane. The FXML structure is simple:

<ScrollPane fx:id="scrollPane" fitToHeight="false" fitToWidth="false" maxHeight="250.0" maxWidth="350.0" minHeight="250.0" minWidth="350.0" prefHeight="250.0" prefWidth="350.0">
  <content>
    <AnchorPane>
      <children>
        <ImageView fx:id="imageView" pickOnBounds="true" preserveRatio="true" smooth="true" />
      </children>
    </AnchorPane>
  </content>
</ScrollPane>

What I'm doing from the code is that I populate the ImageView and than I try to position the image to display the bottom right part. I can achive this seting the vValue and hValue of the Scrollpane to 1.

The problem is the following: when I populate the ImageView for the first time and right after that I try to set the ScrollPane's vValue and hValue properties, the ScrollPane does not change, it still shows the top left part of its content (which is the image). Although setting of the values happens correctly (getVvalue and getHValue return the correct value of 1), the display is not updated.

I'm using this simple code:

    public void openImage(ActionEvent event) throws IOException {

        Image image = new Image("file:///D:/sample.png");

        imageView.setImage(image);

        scrollPane.setVvalue(1);

        scrollPane.setHvalue(1);

    }

And now comes the intersting part: if I call this code within a user action (let's say as part of a button click), for the first time image is loaded but positioning does not happen. For the second time (when user clicks the same button for the second time), the positioning happens.

I also tried to duplicate the above calls (setting image, setting Vvalue and Hvalue, setting image, setting Vvalue and Hvalue) but this is still not working.

Any idea what's causing this behavior and what can be the workaround?

Another, somehow related problem: if I just load the image using the setImage (just like above), it opens the image but does the scroll bars of the ScrollPane do not appear, although the loaded image is larger in size than the ScrollPane- After loading the image if the user click on the image, the scroll bars appear. The workaround I found for this is to use the above setVvalue and setHvalue and set them to 1. Positiong will not happen (just like I described above), but at least the scroll bars will appear. The other solution I found is to use scrollPane.requestFocus();. But still curious what is causing this behaviour. Maybe understanding this would also let me closer to understand the above described, main issue.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 31 2013
Added on Dec 3 2013
0 comments
231 views