简体   繁体   English

如何让 javafx 节点适应它的父节点?

[英]How do I make a javafx node adapt to it´s parent?

Example:例子:

<AnchorPane xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="HomeController">
   <children>
      <VBox fx:id="vBoxParent" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity">
         <children>
            <MenuBar fx:id="menubar" prefHeight="30.0" prefWidth="800.0">

        ...

With this code, the stage opens fullsize, but the menubar isn´t covering all the lenght.使用此代码,舞台以全尺寸打开,但菜单栏并未覆盖所有长度。 What do I have to add?我需要补充什么?

If you want the MenuBar to take the full size of VBox, you can replace VBox with MenuBar, placing MenuBar directly in AnchorPane, and giving Anchor Pane Constraints to the MenuBar (to be responsive).如果您希望 MenuBar 占据 VBox 的完整大小,您可以将 VBox 替换为 MenuBar,将 MenuBar 直接放置在 AnchorPane 中,并为 MenuBar 提供 Anchor Pane Constraints(以进行响应)。

If you want to keep VBox for some reason, you can change the MenuBar properties:如果出于某种原因要保留 VBox,可以更改 MenuBar 属性:

  • set Vgrow to: allways (allways increase the vertical length)将 Vgrow 设置为:allways(始终增加垂直长度)
  • set Max Width to: MAX_VALUE将最大宽度设置为:MAX_VALUE

I recommend you to use SceneBuilder, to easily find functions and preview changes.推荐使用SceneBuilder,方便查找功能和预览变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM