我想重新调整大小的图像,使其适合(缩放)由SplitPane
分配的空间(解决方法建议:此图像将在运行程序时更改,它应该从文本中生成)。我目前使用的ImageView改变了SplitPane
Divider
的位置。分频器永远不会导致ImageView
减少超过图像的大小。JavaFx ImageView不会调整fitWidthProperty绑定到VBox
Two images showing this behavior。
将ImageView
fitWidthProperty链接到VBox
并没有给我预期的调整行为。增加ImageView
的大小确实有效(在没有绑定的情况下修复它),但图像永远不会增长,它只是获得边界。
我MWE:
sample.fxml
:
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<SplitPane orientation="HORIZONTAL" xmlns:fx="http://javafx.com/fxml">
<TextArea fx:id="textArea"/>
<VBox fx:id="vBox" alignment="CENTER">
<HBox fx:id="hBox" alignment="CENTER">
<ImageView fx:id="imageView"/>
</HBox>
</VBox>
</SplitPane>
Controller.java
:
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class Controller {
@FXML
private TextArea textArea = new TextArea();
@FXML
private VBox vBox = new VBox();
@FXML
private HBox hBox = new HBox();
@FXML
private ImageView imageView = new ImageView();
public Controller() {
imageView.fitWidthProperty().bind(vBox.widthProperty());
imageView.fitHeightProperty().bind(hBox.heightProperty());
}
public void start() {
textArea.setText("text");
Image image = new Image("https://www.google.nl/images/srpr/logo11w.png");
imageView.setImage(image);
}
}
和Main.java
:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
final Controller controller = new Controller();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("sample.fxml"));
fxmlLoader.setController(controller);
final Parent root = fxmlLoader.load();
primaryStage.setTitle("MWE");
final Scene scene = new Scene(root, 640, 480);
primaryStage.setScene(scene);
primaryStage.show();
controller.start();
}
public static void main(String[] args) {
launch(args);
}
}
我已经尝试了这个建议,它的工作原理有点,但它会导致'ImageView'增长(约30像素)时,'TextArea'被选中,点击并输入。关于移动分隔符的调整大小行为是我想要的。 – user1658374