- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Scene Builder (v11.0.0) 为 JavaFX (v12) 中的场景创建 FXML 文件,但是,尽管指示所有容器 USE_COMPUTED_SIZE
以获得首选的宽度和高度,渲染的场景(如在 Scene Builder 中所见,以及作为加载这些 FXML 文件的 JavaFX 应用程序运行时)在右侧和底部边缘被剪裁,以便切掉一些节点。
在 Scene Builder 中,渲染器似乎必须知道场景不符合允许的边界,因为编辑器显示蓝色边界标记,这些标记明显超出了渲染矩形。
Scene Builder 中的 View 显示底部需要更多空间以便为按钮提供足够的空间(按钮的底部边缘和 TitledPane
的下边缘缺失)。右侧需要更多空间以适应 DatePicker
和 TitledPane
的右边缘。蓝色边界标记清楚地显示了实际内容结束的位置,因此不清楚为什么显示区域被计算为比这短几个像素。
一旦 FXML 文件用于填充 JavaFX 应用程序中的窗口,就会看到同样的事情:窗口的计算大小是一些太少的像素,无法正确适应整个场景。
如果已正确计算蓝色边界标记以显示需要额外的显示区域宽度和高度,我如何告诉 FXML 在渲染时需要此额外空间?
这是 Scene Builder、FXML 或 JavaFX 中的已知错误/限制吗?或者除了为首选尺寸选择 USE_COMPUTED_SIZE
之外,我还需要做些什么吗?
为了明确这一点,请参阅下面的示例 FXML,它显示了所说明的问题。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TitledPane animated="false" collapsible="false" text="untitled">
<content>
<HBox>
<children>
<fx:include source="subscene.fxml" />
</children>
</HBox>
</content>
</TitledPane>
<TitledPane animated="false" collapsible="false" text="untitled">
<content>
<HBox>
<children>
<fx:include source="subscene.fxml" />
</children>
</HBox>
</content>
</TitledPane>
<TitledPane animated="false" collapsible="false" text="untitled">
<content>
<HBox alignment="BASELINE_RIGHT">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</HBox>
</content>
</TitledPane>
</children>
</VBox>
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="Label" />
<DatePicker />
</children>
</VBox>
最佳答案
这确实是 JavaFX 中的一个错误,特别是 DatePicker
,因为这个简单的示例可以重现该问题:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
VBox root = new VBox(new DatePicker());
// Problem shows up when using USE_COMPUTED_SIZE (the default) as well
root.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
root.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
导致:
注意:将 DatePicker
放入哪个父级似乎无关紧要。其他控件也不会出现此问题。
此问题的解决方法似乎是在调用 show()
之后调用 Window.sizeToScene()
。我不明白为什么这会有所作为,但确实如此。不幸的是,这只会对实际应用有帮助,对 Scene Builder 没有帮助。
关于尽管指定了 USE_COMPUTED_SIZE,JavaFX 和 Scene Builder 仍会剪辑场景边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55403477/
我正在使用 JavaFX 2.2.7-b01 编写应用程序。 这是我目前拥有的代码示例。如何允许调整应用程序窗口的大小但保持最初配置的纵横比?换句话说,如果用户调整窗口大小,则窗口宽度应始终保持为窗口
所以我正在努力将我的 cocos2d 游戏移植到 Sprite Kit。 在 cocos2d 中有两种情况,我会在整个游戏场景中叠加一个菜单。第一种情况是暂停,第二种情况是游戏结束。 在 cocos2
我在代码的最后一行遇到错误。 - (SCNScene *)getWorkingScene { SCNScene *workingSceneView = self.scene; if
我需要在代码中手动设置插入符号位置。getCaretPosition()下有一个javafx.scene.control.TextInputControl,但没有设置方法。 如何设置插入符的位置? 最
方法scene(_ scene: UIScene, continue userActivity: NSUserActivity)用户单击通用链接后启动应用程序时不会调用。 当用户单击通用链接后再次打开
我正在使用 ARKit 图像跟踪配置,一旦检测到图像,图像上就会弹出 3D 场景。 但是当我设置两个不同的图像触发两个不同的场景文件时,一张图像总是在同一张图像上弹出两个不同的场景文件。我敢肯定图像不
如何更改存储在网格中的对象的属性?我尝试了这个,但它给了我上面的错误: Group group = new Group(); double dimension_x=100; d
我在填充 javafx tableview 时遇到问题。 我目前正在开发基于 GUI 的事件管理工具(适用于大学),但我一直在尝试填充 Tableview 列表,该列表应该位于边框 Pane 布局的中
大家好,我认识 javafx,我正在尝试将 BorderPane 转换为 anchronPane,同时发生错误,我不知道该怎么做,我正在学习教程,所以请帮忙 import java.io.IOExce
我有创建图像的代码:(m_img 是 javafx.scene.image.Image) Image m_img = new Image("file:" + p_Fil.getAbsoluteFile
当最初从FXML加载Scene时,如何在Java代码中为Scene添加一个新节点? 我已经从FXML加载了,如下所示 Parent root = FXMLLoader.load(getClass().
在以下代码上: ScrollPane scrollPane = new ScrollPane(); 我遇到异常 java.lang.NoClassDefFoundError: javafx/scene
我从 JavaFX 开始。 错误发生在我执行我的程序时,在我尝试这样做之前,它工作正常并且按钮点击有效,但那是在我打算让按钮点击更改文本之前。
我正在制作一个滑动动画以将一个场景切换到另一个场景,但是当我调用此方法时,它在切换场景时有延迟。我发现原因是类Scene的一个方法snapshot()。有没有人有解决办法? 代码: public vo
当发现“条形码”时,我尝试以编程方式更改场景,但我不断收到错误... 导入的模块: import UIKit import AVFoundation import SpriteKit import S
我试图通过场景工具包节点旋转,但它没有旋转。 我想让它绕 y 轴旋转。它是一个球体。 let node = SCNNode() node.geometry = SCNSphere(radius: 1)
在应该加载场景的按钮中,我正在尝试学习使用 guard 语句,但对它在四个“转义”中的每一个中所做的事情感到非常困惑。也不知道在没有场景的情况下应该怎么处理。 此处正确使用的是: continue、r
本文整理了Java中javafx.scene.input.ZoomEvent类的一些代码示例,展示了ZoomEvent类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Ma
我正在使用 JavaFx 和 Scenebuilder,并希望在 Eclipse 中为自己创建一个名为“Taskplanner”的本地应用程序。 我创建了一个新舞台并使用场景设置它(请参阅 Main.
我在舞台上有一个场景。场景的宽度为 337.0 像素。但是,当我将它添加到舞台时,舞台的大小为 337.6 像素,由于 0.6 像素的差异,在屏幕的右边缘留下了一个白色间隙。 我尝试使用 stage.
我是一名优秀的程序员,十分优秀!