java 格式化 GridPane 以在一行中具有不同的背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12219601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Formatting GridPane to have different background color in one row
提问by The Unfun Cat
gridPane.setStyle("-fx-background-color: #C0C0C0;");
Works and sets the background color of the whole gridpane, but how do I set it for a certain row, eg. row 5?
工作并设置整个网格窗格的背景颜色,但我如何为某一行设置它,例如。第5行?
Do I need to use stylesheets for this? I'd prefer to do it in Java.
我需要为此使用样式表吗?我更喜欢用Java来做。
EDIT:each row contains a label, but the label does not cover the whole row in a pane. If I could set the label to cover the whole row and then set the background color of the label that would be a workaround.
编辑:每一行都包含一个标签,但该标签并未覆盖窗格中的整行。如果我可以将标签设置为覆盖整行,然后设置标签的背景颜色,这将是一种解决方法。
回答by V. Artyukhov
you can add to each grid cell new Pane() object and set background to it.
您可以向每个网格单元添加新的 Pane() 对象并为其设置背景。