JavaFX TextArea & TextField 显示不同的颜色
JavaFX TextArea & TextField display different colors
在我的屏幕上,我想要一个 TextArea 和一个 TextField,我根据内容改变它们的背景颜色。两者都不可编辑(以防万一)。
目前,我正在使用以下命令设置背景:
textArea.setStyle("-fx-control-inner-background: rgba(255,255,0,.5)");
textField.setStyle("-fx-control-inner-background: rgba(255,255,0,.5)");
虽然这正确地设置了颜色,但我的 TextArea 看起来仍然比我的 TextField 亮很多,后者似乎有某种 shadow/shading 正在发生。
为什么会这样,是否可以实现两者相同的外观?
我的同事设法用以下 TextField 代码行解决了这个问题:
-fx-background-color: rgba(255,255,0,.5);
-fx-border-color: derive(-fx-text-box-border, -10%);
-fx-border-radius: 2;
原来应该对 TextFields 使用 -fx-background-color
,对 TextAreas 使用 -fx-control-inner-background
。你知道的越多。
在我的屏幕上,我想要一个 TextArea 和一个 TextField,我根据内容改变它们的背景颜色。两者都不可编辑(以防万一)。
目前,我正在使用以下命令设置背景:
textArea.setStyle("-fx-control-inner-background: rgba(255,255,0,.5)");
textField.setStyle("-fx-control-inner-background: rgba(255,255,0,.5)");
虽然这正确地设置了颜色,但我的 TextArea 看起来仍然比我的 TextField 亮很多,后者似乎有某种 shadow/shading 正在发生。
为什么会这样,是否可以实现两者相同的外观?
我的同事设法用以下 TextField 代码行解决了这个问题:
-fx-background-color: rgba(255,255,0,.5);
-fx-border-color: derive(-fx-text-box-border, -10%);
-fx-border-radius: 2;
原来应该对 TextFields 使用 -fx-background-color
,对 TextAreas 使用 -fx-control-inner-background
。你知道的越多。