JavaFX:选择/聚焦时组件/节点会发生变化

发布于 2024-09-11 19:36:57 字数 1523 浏览 1 评论 0原文

我正在创建一个非常简单的表单,并且遇到了控件/组件在选择时将位置(特别是文本框和复选框)移动几个像素的问题。它绝不破坏我的界面,但你可以想象它有点刺激。我感觉这是我创建的自定义节点的问题......尽管我无法确定问题出在哪里。

我之前做过类似的事情,没有遇到任何麻烦,但自从我尝试“模块化”我的代码(创建一个带有标签和文本框的自定义节点,而不是在主文件中单独声明每个节点)后,我遇到了这个(以及其他一些微妙的问题)问题)。这是我的自定义节点...以防万一这可以解决我的问题。

public class NumberWithLabelNode extends CustomNode {

public var width: Number;
public var height: Number;
public var x: Number;
public var y: Number;
public var labelText: String = "Generic Label:  ";
public var text: String = "0.0";
public var columns: Integer = 5;
public var error: Boolean = false;
public var errorText: String = "  Invalid input.";

public override function create(): Node {
    return HBox {
                width: bind width
                height: bind height
                content: [
                    Text {
                                content: bind labelText
                            },
                    TextBox {
                        layoutInfo: LayoutInfo { hgrow: Priority.NEVER }
                        columns: bind columns
                        text: bind text with inverse
                    },
                    Text {
                        visible: bind error
                        fill: Color.RED
                        content: bind errorText;
                    }
                ]
            }
}

如果

您发现我做错了什么/不遵循标准,请告诉我。重申一下,我希望这个自定义节点的行为与我在 hbox 中创建标签和文本框完全相同。

我希望有人至少可以引导我找到我的问题所在的方向,而不必查看我的源代码的其余部分(可能是一个长期的机会......我希望不必删除代码在这里发帖)。

提前致谢!

I'm creating a pretty simple form, and I'm running into an issue with Controls/components shifting position (textboxes and checkboxes in particular) by a few pixels upon selection. It's by no means breaking my interface, but you can imagine it's a bit of an irritant. I have a feeling it's an issue with the custom node(s) I've created... though I can't determine where the problem would be.

I did something similar before without any trouble, but ever since I tried "modularizing" my code (created a custom node with label and texbox opposed to separately declaring each in the main) I've come across this (along with a few other subtle issues). Here is my custom node... in case this gives way to figuring out my problem.

public class NumberWithLabelNode extends CustomNode {

public var width: Number;
public var height: Number;
public var x: Number;
public var y: Number;
public var labelText: String = "Generic Label:  ";
public var text: String = "0.0";
public var columns: Integer = 5;
public var error: Boolean = false;
public var errorText: String = "  Invalid input.";

public override function create(): Node {
    return HBox {
                width: bind width
                height: bind height
                content: [
                    Text {
                                content: bind labelText
                            },
                    TextBox {
                        layoutInfo: LayoutInfo { hgrow: Priority.NEVER }
                        columns: bind columns
                        text: bind text with inverse
                    },
                    Text {
                        visible: bind error
                        fill: Color.RED
                        content: bind errorText;
                    }
                ]
            }
}

}

If you see anything I've done incorrectly/doesn't follow standards, please let me know. To re-iterate, I want this custom node to behave exactly as if I created a label and textbox in an hbox.

I'm hoping somebody can at least guide me in the direction of where my issue could be without having to look at the rest of my source (may be a long shot... I'm hoping to not have to strip down code to post here).

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

讽刺将军 2024-09-18 19:37:02

这可能无法解决问题,但会有所帮助:

您不应该自己设置任何可调整大小的宽度/高度。父容器为您设置它们。如果您希望某个对象具有特定大小,请改用 LayoutInfo 对象。

This might not fix the issue, but will help:

You are not supposed to set width/height of any Resizable yourself. The parent container sets them for you. If you wish an object to be specifically sized use LayoutInfo object instead.

一曲琵琶半遮面シ 2024-09-18 19:37:02

我最终让事情变得更符合我的喜好。我最终扩展了 CustomNode 和 Resizable(并实现了 Ressized 所需的方法......请参阅 API)。我发现这很有帮助 -> http://blog.cedarsoft.com/2010/05 /javafx-template-for-ressized-customnode/

需要注意的是:CustomNode 不是可调整大小的。 JFXtras 添加了一个名为 XCustomNode 的节点,该节点添加了(缺少的)可调整大小功能。 JFXtras 库可以在 code.google.com/p/jfxtras/downloads/list 找到(抱歉...现在只能发布 1 个链接)。如果您使用 JavaFX 1.3,请坚持使用 0.7 版本。 0.6 版本可与 JavaFX 1.2 配合使用。

I ended up getting things working more to my liking. I ended up extending both CustomNode and Resizable (and implementing the needed methods for Resizable... see API). I found this helpful -> http://blog.cedarsoft.com/2010/05/javafx-template-for-resizable-customnode/.

Something to note: CustomNode is not a Resizable. JFXtras adds a Node called XCustomNode that adds the (missing) Resizable feature(s). The JFXtras libraries can be found at code.google.com/p/jfxtras/downloads/list (sorry... can only post 1 link right now). Stick to the 0.7 builds if you're using JavaFX 1.3. The 0.6 versions work with JavaFX 1.2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文