Regarding issue with JavaFX 8 ScrollPane
Mong Hang Vo
hang.vo at oracle.com
Mon Jul 28 01:15:46 UTC 2014
Vadala,
I don't have a good answer to your question. So I am adding the
openjfx-dev at openjdk.java.net alias.
In the future, please send your question to this alias.
Thank you very much,
Mong
Vadala, Sirish wrote:
>
> Hello Hang,
>
>
>
> My name is Sirish Vadala, working for Legislative Data Center,
> Sacramento, California. Right now I am working on a project
> implemented on JavaFX 8 (jdk1.8.0_05) and have a quick question on one
> of the UI related issues that my team is facing.
>
>
>
> Coming to the issue I am not able to programmatically place the
> ScrollPane's scroll position using setVValue(double) method of
> ScrollPane. For example, if you look at the sample program below, the
> vertical scroll bar position always remains on the top what so ever
> the vValue is set to. Can you please let me know if this is an
> existing issue being worked on or if I am doing something wrong in
> implementation?
>
>
>
> I highly appreciate your response at your convenience on this issue.
>
>
>
> import java.awt.image.BufferedImage;
>
> import java.io.File;
>
> import java.io.IOException;
>
> import java.util.logging.Level;
>
> import java.util.logging.Logger;
>
> import javafx.application.Application;
>
> import javafx.embed.swing.SwingFXUtils;
>
> import javafx.event.ActionEvent;
>
> import javafx.event.EventHandler;
>
> import javafx.scene.Scene;
>
> import javafx.scene.control.Button;
>
> import javafx.scene.control.ScrollPane;
>
> import javafx.scene.control.ScrollPane.ScrollBarPolicy;
>
> import javafx.scene.image.Image;
>
> import javafx.scene.image.ImageView;
>
> import javafx.scene.layout.VBox;
>
> import javafx.stage.FileChooser;
>
> import javafx.stage.Stage;
>
> import javax.imageio.ImageIO;
>
> public class JavaFXPixel extends Application {
>
>
>
> private ImageView myImageView;
>
> private ScrollPane scrollPane;
>
>
>
> @Override
>
> public void start(Stage primaryStage) {
>
>
>
> Button btnLoad = new Button("Load");
>
> btnLoad.setOnAction(btnLoadEventListener);
>
>
>
> myImageView = new ImageView();
>
>
>
> scrollPane = new ScrollPane();
>
> scrollPane.setPrefSize(300, 250);
>
> scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
>
> scrollPane.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
>
> scrollPane.setContent(myImageView);
>
>
>
> // STILL MY VERTICAL SCROLL POSITION IS ALWAYS PLACED ON THE TOP
>
> scrollPane.setVvalue(1.0);
>
>
>
> VBox rootBox = new VBox();
>
> rootBox.getChildren().addAll(btnLoad, scrollPane);
>
>
>
> Scene scene = new Scene(rootBox, 300, 300);
>
>
>
> primaryStage.setTitle("My Test Program");
>
> primaryStage.setScene(scene);
>
> primaryStage.show();
>
>
>
> }
>
> public static void main(String[] args) {
>
> launch(args);
>
> }
>
>
>
> private final EventHandler<ActionEvent> btnLoadEventListener =
> (ActionEvent t) -> {
>
> FileChooser fileChooser = new FileChooser();
>
>
>
> //Set extension filter
>
> FileChooser.ExtensionFilter extFilterJPG = new
> FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
>
> FileChooser.ExtensionFilter extFilterPNG = new
> FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
>
> fileChooser.getExtensionFilters().addAll(extFilterJPG,
> extFilterPNG);
>
>
>
> //Show open file dialog
>
> File file = fileChooser.showOpenDialog(null);
>
>
>
> try {
>
> BufferedImage bufferedImage = ImageIO.read(file);
>
> Image image = SwingFXUtils.toFXImage(bufferedImage, null);
>
> myImageView.setImage(image);
>
> scrollPane.setContent(null);
>
> scrollPane.setContent(myImageView);
>
> scrollPane.setVvalue(1.0);
>
> } catch (IOException ex) {
>
>
> Logger.getLogger(JavaFXPixel.class.getName()).log(Level.SEVERE, null, ex);
>
> }
>
> };
>
> }
>
>
>
> Thanks.
>
> Sirish Vadala
>
> 916 341 8878
>
More information about the openjfx-dev
mailing list