如何禁用节点而不在JavaFX中将其灰显?

You*_*147 5 css java javafx

我的问题是能够禁用Node用户在打印时无法与之交互的问题.但是,出于同样的原因,我需要整体Node(在这种情况下为a GridPane)及其所有子代(主要是按钮和标签)在打印进行时不能由用户进行交互.

当我写作时setDisable,它会将整体渲染Node出来,但我希望保留原来的颜色和状态Node.

有没有办法做到这一点?通过disableProperty或其他方式,对我来说并不特别重要.这里的关键是你不应该与之交互Node.

提前致谢

You*_*147 7

我找到了答案:

来自@awksp"JavaFX中的所有节点都有一个setMouseTransparent()方法,详见此处,mouseTransparent属性为:

If true, this node (together with all its children) is completely transparent to mouse events. When choosing target for mouse event, nodes with mouseTransparent set to true and their subtrees won't be taken into account...."

然后我进一步使用setFocusTraversable(false),这样你就无法通过其他方式集中来与Node交互

感谢@awksp的帮助:https://stackoverflow.com/a/24164911/6197978


DVa*_*rga 6

你可以看看modena.css

/* ====   DISABLED THINGS   ================================================= */
.label:disabled,
.button:disabled,

 ... a lot more control here ...

.table-cell:selected:disabled,
.tree-table-cell:selected:disabled {
    -fx-opacity: 0.4;
}
Run Code Online (Sandbox Code Playgroud)

This means when the disabledselector is present, it will set the -fx-opacityattribute to 0.4 from the default 1.0.

不透明度在概念上可以被认为是一种后处理操作。从概念上讲,在节点(包括其后代)渲染为 RGBA 离屏图像后,不透明度设置指定如何将离屏渲染混合到当前复合渲染中。

您可以在 css 中包含此内容,以删除任何控件上的不透明度更改:

* :disabled {
    -fx-opacity: 1;
}
Run Code Online (Sandbox Code Playgroud)