- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我初始化了一些不是我的锚定 Pane 的元素:
AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), fieldLoader.load(), menuLoader.load(), buttonLoader.load());
但是当我尝试单击菜单栏或 ListView 时,它不起作用。例如,在本例中,我可以单击按钮(也许),因为它是我在 AnchorPane 构造函数中初始化的最后一个元素。我无法使用 BorderPane 或任何其他布局,因此我需要找到具有此配置的解决方案。这些是我的 fxml 文件:
list.fxml
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ListController">
<children>
<AnchorPane>
<children>
<ListView fx:id="listView" layoutX="1.0" layoutY="31.0" prefHeight="371.0" prefWidth="239.0" />
</children>
</AnchorPane>
</children>
menuBar.fxml
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.MenuBarController">
<children>
<AnchorPane>
<children>
<MenuBar fx:id="menuBar" layoutX="0.0" layoutY="0.0">
<menus>
<Menu text="File">
<items>
<MenuItem onAction="#elimina" text="Elimina" />
</items>
</Menu>
<Menu text="Cambia Account">
<items>
<MenuItem fx:id="email1" text="filippo@hotmail.it" />
<MenuItem fx:id="email2" text="giancarlo@yahoo.it" />
<MenuItem fx:id="email3" text="alessandro@gmail.it" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</AnchorPane>
</children>
textArea.fxml
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="mailbox.TextAreaController">
<children>
<AnchorPane>
<children>
<TextArea fx:id="textarea" editable="false" layoutX="246.0" layoutY="255.0" prefHeight="144.0" prefWidth="350.0" />
</children>
</AnchorPane>
</children>
button.fxml
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.ButtonController">
<children>
<AnchorPane>
<children>
<Button id="scrivi" layoutX="268.0" layoutY="200.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="65.0" text="Scrivi" />
<Button id="reply" layoutX="342.0" layoutY="200.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="65.0" text="Reply" />
<Button id="replyall" layoutX="420.0" layoutY="200.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="75.0" text="Reply-All" />
<Button id="forward" layoutX="511.0" layoutY="200.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="75.0" text="Forward" />
</children>
</AnchorPane>
</children>
textfield.fxml
<AnchorPane mouseTransparent="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mailbox.TextFieldController">
<children>
<AnchorPane>
<children>
<TextField fx:id="id" editable="false" layoutX="355.0" layoutY="39.0" mouseTransparent="false" prefHeight="27.0" prefWidth="35.0" />
<TextField fx:id="mitt" editable="false" layoutX="355.0" layoutY="72.0" mouseTransparent="false" prefHeight="27.0" prefWidth="182.0" />
<TextField fx:id="dest" editable="false" layoutX="355.0" layoutY="108.0" mouseTransparent="false" prefHeight="27.0" prefWidth="182.0" />
<TextField fx:id="oggetto" editable="false" layoutX="355.0" layoutY="144.0" mouseTransparent="false" prefHeight="27.0" prefWidth="182.0" />
<TextField fx:id="data" editable="false" layoutX="437.0" layoutY="39.0" mouseTransparent="false" prefHeight="27.0" prefWidth="100.0" />
<Label layoutX="329.0" layoutY="44.0" text="ID:" />
<Label layoutX="291.0" layoutY="77.0" text="Mittente:" />
<Label layoutX="398.0" layoutY="44.0" text="Data:" />
<Label layoutX="268.0" layoutY="113.0" text="Destinatario:" />
<Label layoutX="292.0" layoutY="149.0" text="Oggetto:" />
</children>
</AnchorPane>
</children>
最佳答案
AnchorPane
如果您正在设计响应式布局,则这是最糟糕的布局之一,因为它不允许您在定位子级时考虑其他子级的大小(除非您使用监听器/绑定(bind)来更新布局参数)。
在这种特定情况下,您的问题是您的 button.fxml
覆盖其他 fxml 的所有内容,因此接收所有 MouseEvent
s。要可视化 fxml 覆盖的区域,只需将此属性添加到 button.fxml
的根部即可。 :style="-fx-background-color: rgba(0, 0, 255, 0.5)"
.
一个可能的解决方法是使子 fxml 尽可能小并指定父级中的根位置:
确定最小值layoutX
和layoutY
内在的 children 的<AnchorPane>
,为根设置这些值(或将它们添加到根的先前值),并从内部 <AnchorPane>
的所有子项中减去这些值。 .
<!-- specify min layoutX/Y as position for root -->
<AnchorPane xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1"
layoutX="268"
layoutY="200"
fx:controller="mailbox.ButtonController">
<children>
<AnchorPane>
<children>
<!-- subtract root layoutX/Y from positions -->
<Button id="scrivi" mnemonicParsing="false" prefHeight="27.0"
prefWidth="65.0" text="Scrivi" />
<Button id="reply" layoutX="74" mnemonicParsing="false"
prefHeight="27.0" prefWidth="65.0" text="Reply" />
<Button id="replyall" layoutX="152" mnemonicParsing="false"
prefHeight="27.0" prefWidth="75.0" text="Reply-All" />
<Button id="forward" layoutX="243" mnemonicParsing="false"
prefHeight="27.0" prefWidth="75.0" text="Forward" />
</children>
</AnchorPane>
</children>
</AnchorPane>
(对其他 fxml 进行相应操作。)
以这种方式覆盖节点仍然是一个糟糕的想法,因为您使用的是绝对位置,并且对其中一个 fxml 的任何修改都可能需要您更新多个其他节点以避免覆盖。更糟糕的是,根据操作系统/设置的不同,情况看起来也会有所不同。对于一种操作系统,场景可能看起来不错,但在另一种操作系统上,您的节点可能会重叠。
因此,我建议避免使用绝对定位,除非您 100% 确定节点大小已知。使用 BorderPane
可以更好地创建如图所示的场景。/HBox
/VBox
和/或 GridPane
...
关于java - AnchorPane 元素忽略鼠标单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53391994/
我正在编写一个 JavaFX 应用程序,顶部有一个菜单栏,下面有一个 AnchorPane,我可以在其中使用其他 FXML 文件来显示内容。问题是当代码运行时,即使我将 Vgrow 设置为“始终”,其
正如标题所示,我创建了一个根 AnchorPane,其中放置了两个 AnchorPane,上部 AnchorPane 以某种方式变得圆滑,但在下部 AnchorPane 的情况下,上侧是圆角的,而下侧
所以我正在致力于构建一个类似于 IDE 的应用程序,例如 Eclipse 或 Netbeans。我想要有不同的区域,用户可以选择一些内容,例如将显示在其中一个区域中的 View 。我的第一次尝试是将控
我想创建一个基于GridPane的应用程序。为了实现自适应性,我使用 AnchorPane。布局在宽度上延伸得很好,但在高度上却很糟糕。如何修复?
我有一个 TabPane,其中包含两个 Tab,并在 FXML 中设置。初始化时,我动态地将 AnchorPane 添加到 Tab 之一。然后,我将 ListView 设置为 AnchorPane 的
所以我对这个有点卡住了。我有一个非常基本的游戏,你可以用箭头键在网格中移动一艘船。 我添加了另一个线程,其中包含一些应该自动在网格中漫游的怪物。我可以从打印语句中看到线程正在运行并且怪物正在移动,但是
我初始化了一些不是我的锚定 Pane 的元素: AnchorPane root = new AnchorPane(listLoader.load(), textareaLoader.load(), f
对于一个项目,我得到了代码并且必须将其重构为 FXML,我正在尝试使用我得到的一段代码,它是 AnchorPane 的扩展,但是当我在 FXML 中将其从 AnchorPane 切换到 World 时
我正在尝试使鼠标事件在我的 javaFx 中工作。我希望能够向我的 anchor 面板添加鼠标事件,但我似乎无法使其工作。 room = new AnchorPane(); r
您好,我有以下代码,我在 anchor Pane 内添加一个圆圈,并在圆圈上添加文本。 Circle是一个Circle,ArrayList,有多个圆圈。 pane.getChildren().
我有一列有 3 行。每行包含一个图像。此列是 GridPane 的子项。如您在以下 FXML 中所见:
我在 AnchorPane 内有一个 JavaFX Label,它包含在 VBox 中。这个位于 ScrollPane 中。我希望文本自动换行并自动适应窗口的宽度。 这是我的代码的简化示例: publ
这似乎是一个简单的问题,但我还没有找到相关的答案。 我正在创建一个简单的 Javafx 应用程序,并在单击时创建可以拖动的节点。 我想确保特定类型的节点(圆形)始终绘制在 AnchorPane 顶部。
我正在做一个项目,我需要你的帮助。 我想知道是否可以将 percentage 中的锚定 Pane 约束设置为类似 AnchorPane.setLeftAnchor(content1, 35%); 最佳
我正在使用 SceneBuilder 8.0.0 和 JavaFX 8。 我有一个 Button btn 和一个 Label lbl 附加到 AnchorPane ap。 当应用程序启动时,btn 和
我有 AnchorPane根 根目录下的HBox HBox中有两个VBox,每个都没有名字,new AnchorPane和带有文本的每个 AnchorPane 中的无名标签 有表格,只是模板不适合我。
我正在使用 sceneBuilder。 How to clear an AnchorPane ? Is there a way to delete all the nodes contained in
我希望我的 Javafx 组件(如标签、TextFields 分别包装在 VBox 中)保持在窗口的中央,即使它已调整大小。见附件图片。目前这些组件包含在 anchorPane 中。FXML 文件代码
我正在 javafx 中创建一个小应用程序。我想设置背景颜色,所以以下是我的 FXML 代码..我需要如何设置背景颜色
我会将我的锚定 Pane 打印为 png:我在我的 Controller 中加载了一个图像并写了一些文本,而不是我想保存整个面板,但我不知道我必须使用哪些工具。 URL fxmlpath = this
我是一名优秀的程序员,十分优秀!