webview没有´;t在javafx中使用屏幕最大化
我正在使用scenebuilder,我希望我的应用程序有一个横向工具栏和一个webview。我遇到的问题是,当我最大化屏幕时,webview的大小保持不变,而窗格变大。我试过使用Stackpane,但不起作用。目前的结构如下所示:webview没有´;t在javafx中使用屏幕最大化,java,javafx,Java,Javafx,我正在使用scenebuilder,我希望我的应用程序有一个横向工具栏和一个webview。我遇到的问题是,当我最大化屏幕时,webview的大小保持不变,而窗格变大。我试过使用Stackpane,但不起作用。目前的结构如下所示: Pane VBox StackPane WebView 编辑:我尝试过其他方法,例如,这样可以调整大小,但stackpane会填满整个屏幕,没有vBox的位置 AnchorPane VBox StackPane Web
Pane
VBox
StackPane
WebView
编辑:我尝试过其他方法,例如,这样可以调整大小,但stackpane会填满整个屏幕,没有vBox的位置
AnchorPane
VBox
StackPane
WebView
我的fxml
<AnchorPane fx:id="anchor" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.BrowserController">
<children>
<VBox fx:id="vbox" prefHeight="600.0" prefWidth="200.0" style="-fx-background-color: red;" />
<StackPane fx:id="subPane" alignment="CENTER_RIGHT" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<WebView fx:id="webview" prefWidth="600.0" />
</children>
</StackPane>
</children>
</AnchorPane>
查找一些关于
JavaFX
布局的教程。如果我没弄错你的意思,这就行了VBox
、HBox
和GridPane
非常适合处理不断增长的布局。本例中的键是HBox
。将左侧VBox
设置为给定宽度,并将WebView
设置为HBox.vgrow=“始终”
窗格
只是将子对象的大小调整为首选大小。使用此布局无法获得响应性布局…您有何建议?但如何实现类似的效果?发布您的FXML
。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.web.WebView?>
<VBox prefHeight="443.0" prefWidth="678.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.BrowserController">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<HBox prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<children>
<VBox fx:id="vbox" prefHeight="600.0" prefWidth="200.0" style="-fx-background-color: red;" />
<WebView fx:id="webview" prefWidth="600.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>