gpt4 book ai didi

JavaFX 焦点按钮下划线

转载 作者:行者123 更新时间:2023-12-02 03:14:10 24 4
gpt4 key购买 nike

我制作了按钮,并用矩形塑造了它的形状并更改了背景颜色。

<小时/>

源代码:
MainApplication.java:

AnchorPane anchor  = new AnchorPane();
anchor.maxWidth(325);
Button[] buttons = new Button[3];
String[] buttonName = new String[]{"Player","World","Log"};
for (int i = 0 ; i < 3 ; i ++){
Button button = new Button();
button.setText(buttonName[i]);
button.setShape(new Rectangle(100, 25));
button.setMaxWidth(100);
button.setMinWidth(100);
button.setMaxHeight(25);
button.setMinHeight(25);
button.setId("tabButton");
StackPane stack = new StackPane();
stack.setMaxWidth(100);
stack.setMaxHeight(25);
stack.setMinWidth(100);
stack.setMinHeight(25);
RippingCircle circle = new RippingCircle();//just a rippleAnimation
circle.setToSize(Math.sqrt(100 * 100 + 25 * 25));
circle.setFromSize(0.0);
circle.setFill(Color.rgb(0, 0, 0, 0.2));
Rectangle clip = new Rectangle(-50, -12.5, 100, 25);
circle.setClip(clip);
stack.getChildren().addAll(button, circle);
stack.setLayoutX(100 * i);
stack.setLayoutY(0);
button.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent){
StackPane.setMargin(circle, new Insets((mouseEvent.getY() - 12.5) * 2, 0, 0, (mouseEvent.getX() - 50) * 2));
clip.setX(-mouseEvent.getX());
clip.setY(-mouseEvent.getY());
circle.play();
}
});
button.setOnMouseReleased(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent){
circle.stop();
}
});
anchor.getChildren().add(stack);
buttons[i] = button;
}

MainApplication.css:

#tabButton {
-fx-background-color: #03A9F4;
-fx-text-fill: rgba(150,255,255,255);
-fx-font: 12 Arial;
-fx-focus-color: #FFEB3B;
-fx-faint-focus-color: #FFEB3B;
-fx-accent: #FFEB3B;
}
#tabButton:hover {
-fx-background-color: #039BE5;
-fx-text-fill: rgba(150,255,255,255);
-fx-font: 12 Arial;
-fx-focus-color: #FFEB3B;
-fx-faint-focus-color: #FFEB3B;
-fx-accent: #FFEB3B;
}
#tabButton:focused {
-fx-background-color: #03A9F4;
-fx-text-fill: rgba(255,255,255,255);
-fx-font: 12 Arial;
-fx-focus-color: black;
-fx-faint-focus-color: black;
}
<小时/>

当它聚焦时,Player 按钮下方会出现一条下划线:

enter image description here

像这样。
这个下划线是什么?如何更改它的颜色?

最佳答案

我认为它属于焦点,如果你想隐藏它:

-fx-background-insets:0;

或者改变颜色:

-fx-focus-color: red;
-fx-faint-focus-color: red;

祝你好运!

关于JavaFX 焦点按钮下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40561275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com