[英]Java FX buttons slightly smaller when clicked/focus
I have an issue where my buttons in JavaFX become slightly smaller when clicked.我有一个问题,即我在 JavaFX 中的按钮在单击时会变小。
here you can see that the "change password" button is clicked/selected.在这里您可以看到单击/选择了“更改密码”按钮。
here you can see the "admin functions" button is clicked/selected.在这里您可以看到单击/选择了“管理功能”按钮。
I suspected this was something to do with the buttons having focus, as when i click chrome or another application with this running, it reverts to desired look我怀疑这与具有焦点的按钮有关,因为当我单击 chrome 或其他正在运行的应用程序时,它会恢复到所需的外观
the buttons are currently within a 4x1 GridPane, with the 0th slot being occupied by the label.按钮当前位于 4x1 GridPane 中,第 0 个插槽被标签占用。
here is my CSS if it helps:如果有帮助,这是我的 CSS:
.button{
-fx-border-color: null;
-fx-border-width: 0;
-fx-background-color: #2c3cff;
-fx-fill: true;
-fx-pref-height: 100;
-fx-pref-width: 320;
-fx-text-fill: #b9b9b9;
-fx-border-radius: 0;
-fx-min-width: 320;
-fx-min-height: 100;
-fx-background-radius: 0;
-fx-animated: false;
}
.grid{
-fx-background-color:#3e3e48;
}
.label{
-fx-text-fill: #b9b9b9;
}
Edit: I have found a temporary "solution", more of a workaround: I put a horizontal separator just below my HBox and this allowed me to mask the weird button size changes.
编辑:我找到了一个临时的“解决方案”,更多的是一种解决方法:我在 HBox 下方放置了一个水平分隔符,这使我可以掩盖奇怪的按钮大小变化。 would still like answers about how to do this properly.
仍然想要有关如何正确执行此操作的答案。
Thanks!
谢谢!
So, I figured it out after a long time of trying to use workarounds such as the separator.因此,经过长时间尝试使用诸如分隔符之类的变通方法后,我想通了。
The default FX stylesheet applied this to all buttons:默认的 FX 样式表将此应用于所有按钮:
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
and whilst in my .button:focused
definition i had set these to 0, in my .button
definition i had not, so it had taken the insets value from the default CSS.虽然在我的
.button:focused
定义中我已经将这些设置为 0,但在我的.button
定义中我没有,所以它从默认 CSS 中获取了 insets 值。 by applying -fx-background-insets: 0,0,0,0,0;
通过应用
-fx-background-insets: 0,0,0,0,0;
to both .button
and .button:hover
i was able to achieve the desired result. .button
和.button:hover
我都能够达到预期的结果。
Note: you can just type
-fx-background-insets: 0;
注意:你可以输入
-fx-background-insets: 0;
i left the full values in in case i want to change at a later date.我留下了完整的值,以防我想在以后更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.