我的问题是能够禁用Node
,以便用户在打印时无法与其进行互动。但是,出于同样的原因,我需要整体Node
(在这种情况下为GridPane
)及其所有子项(主要是按钮和标签)不能被用户交互,而打印是继续。
当我写setDisable
时,它会使整个Node
变灰,但我希望在Node
禁用时保留原始颜色和状态。
有办法做到这一点吗?通过disableProperty
或其他方式,对我来说并不特别重要。这里的关键是你不应该与Node
进行互动。
提前致谢
答案 0 :(得分:5)
我找到了答案:
来自@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)
,这样您就无法通过其他方式将节点与其进行交互
感谢@awksp的帮助: https://stackoverflow.com/a/24164911/6197978
答案 1 :(得分:4)
css可以解决您的问题使用禁用属性。并更改背景和文字颜色。 以下是组合框的CSS,但你可以参考它的一部分。
.transparent:disabled, .transparent:disabled .arrow-button .arrow, .transparent:disabled .combo-box-base {
-fx-background-color: #ffffff;
-fx-opacity: 1;
-fx-text-fill:#000000;
}
有关详细信息,请参阅javafx中css参考指南的以下链接
https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html
答案 2 :(得分:4)
您可以查看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;
}
这意味着当disabled
选择器出现时,它会将-fx-opacity
属性设置为默认值1.0的0.4。
不透明度在概念上可以被认为是后处理操作。 从概念上讲,在渲染节点(包括其后代)之后 进入RGBA屏外图像,不透明度设置指定如何 将屏幕外渲染混合到当前的复合渲染中。
您可以在css中添加此内容,以删除任何控件上的不透明度更改:
* :disabled {
-fx-opacity: 1;
}
答案 3 :(得分:1)
在我的情况下,我正在制作TicTacToe游戏,在按下该按钮后我需要禁用该按钮,但是不透明度与以前相同,因此我只设置了不透明度。
喜欢这个...
public void actions(){
one.setOnMouseClicked(e->{
one.setText("X");
one.setDisable(true);
one.setOpacity(1);
});
}
我希望它可以帮助某人。
答案 4 :(得分:0)
如果要使特定的窗格不灰显,可以向其添加以下CSS样式表。
JavaFX
node.getStyleClass().add("pane_opacity");
CSS
.pane_opacity:disabled .label:disabled,
.pane_opacity:disabled .button:disabled,
.pane_opacity:disabled .toggle-button:disabled,
.pane_opacity:disabled .radio-button:disabled,
.pane_opacity:disabled .check-box:disabled,
.pane_opacity:disabled .hyperlink:disabled,
.pane_opacity:disabled .menu-button:disabled,
.pane_opacity:disabled .split-menu-button:disabled,
.pane_opacity:disabled .slider:disabled,
.pane_opacity:disabled .scroll-bar:disabled,
.pane_opacity:disabled .scroll-pane:disabled,
.pane_opacity:disabled .progress-bar:disabled,
.pane_opacity:disabled .progress-indicator:disabled,
.pane_opacity:disabled .text-input:disabled,
.pane_opacity:disabled .choice-box:disabled,
.pane_opacity:disabled .combo-box-base:disabled,
.pane_opacity:disabled .date-cell:disabled > *, /* This is set on children so border is not affected. */
.pane_opacity:disabled .list-view:disabled,
.pane_opacity:disabled .tree-view:disabled,
.pane_opacity:disabled .table-view:disabled,
.pane_opacity:disabled .tree-table-view:disabled,
.pane_opacity:disabled .tab-pane:disabled,
.pane_opacity:disabled .titled-pane:disabled > .title,
.pane_opacity:disabled .accordion:disabled > .titled-pane > .title,
.pane_opacity:disabled .tab-pane > .tab-header-area > .headers-region > .tab:disabled,
.pane_opacity:disabled .menu:disabled,
.pane_opacity:disabled .menu-item:disabled > .label,
.pane_opacity:disabled .menu-item:disabled,
.pane_opacity:disabled .list-cell:filled:selected:focused:disabled,
.pane_opacity:disabled .list-cell:filled:selected:disabled,
.pane_opacity:disabled .tree-cell:filled:selected:focused:disabled,
.pane_opacity:disabled .tree-cell:filled:selected:disabled,
.pane_opacity:disabled .tree-cell > .tree-disclosure-node:disabled,
.pane_opacity:disabled .tree-table-row-cell > .tree-disclosure-node:disabled,
.pane_opacity:disabled .table-row-cell:selected:disabled,
.pane_opacity:disabled .tree-table-row-cell:selected:disabled,
.pane_opacity:disabled .table-cell:selected:disabled,
.pane_opacity:disabled .tree-table-cell:selected:disabled {
-fx-opacity: 1;
}
答案 5 :(得分:0)
使用node.setDisable(true);
禁用节点,使用node.setStyle("-fx-opacity: 1");
防止节点失去透明度。