我遇到了JavaFX和FXML的问题。 我有一个简单的FXML文件以这种方式构建:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.media.MediaView?>
<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="480.0" minWidth="720.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mediaplayer.MediaPlayerControllerSplit">
<center>
<SplitPane dividerPositions="0.5" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" BorderPane.alignment="CENTER">
<items>
<AnchorPane fx:id="mediaPaneL" style="-fx-background-color: green;">
<children>
<MediaView fx:id="mediaViewL" />
</children>
</AnchorPane>
<AnchorPane fx:id="mediaPaneR" style="-fx-background-color: red;">
<children>
<MediaView fx:id="mediaViewR" />
</children>
</AnchorPane>
</items>
</SplitPane>
</center>
<bottom>
<ToolBar minHeight="-Infinity" minWidth="-Infinity" style="-fx-background-color: black;" BorderPane.alignment="BOTTOM_CENTER">
<items>
<Button mnemonicParsing="false" onAction="#openVideo" text="Openfile" />
<Button mnemonicParsing="false" onAction="#playVideo" text=">" />
<Button mnemonicParsing="false" onAction="#pauseVideo" text="||" />
<Button mnemonicParsing="false" onAction="#stopVideo" text="stop" />
<Button mnemonicParsing="false" text="<<<" />
<Button mnemonicParsing="false" text="<<" />
<Button mnemonicParsing="false" text=">>" />
<Button mnemonicParsing="false" text=">>>" />
<Button mnemonicParsing="false" onAction="#exitVideo" text="EXIT" />
</items>
</ToolBar>
</bottom>
</BorderPane>
控制器将加载2个视频并在SplitView内的相对2个AnchorPanes中显示它们,如下图所示: ClickMe
视频超出了父级AnchorPane的宽度范围,我该如何正确设置它们? 谢谢大家。
答案 0 :(得分:0)
我用Controller类中的以下代码行解决了这个问题:
mediaViewL.fitWidthProperty().bind(mediaPaneL.widthProperty());
左侧(右侧相同)mediaView宽度已经适合他的第一个父宽度(AnchorPaneL / AnchorPaneR)。