gpt4 book ai didi

css - 使用 JavaFx 的文本字段 CSS 样式

转载 作者:行者123 更新时间:2023-12-05 01:12:55 25 4
gpt4 key购买 nike

我正在尝试使用 JavaFX 设置一些文本字段的样式,但没有得到想要的结果。我的目标是让文本字段由单个下划线表示。这是我的 CSS:

.text-field{
-fx-font-family: "Quicksand";
-fx-font-size: 18;
-fx-padding: 1,1,1,1;
-fx-border-color: grey;
-fx-border-width: 2;
-fx-border-radius: 1;
-fx-border: gone;
-fx-background-color: transparent;
-fx-text-fill: grey;
}

我已经研究过这个问题,但是我找到的类似问题的答案并没有真正包含足够的信息来重现并正确应用于我的程序。我对 CSS 样式不是很了解,这无济于事。我尝试使用插入结果最小。感谢您提供的任何答案!

最佳答案

以下对我有用:

/* File style.css */

.text-field {
-fx-background-color: -fx-text-box-border, -fx-background ;
-fx-background-insets: 0, 0 0 1 0 ;
-fx-background-radius: 0 ;
}
.text-field:focused {
-fx-background-color: -fx-focus-color, -fx-background ;
}

以下测试工具为此
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class TextFieldStyleTest extends Application {

@Override
public void start(Stage primaryStage) {
GridPane root = new GridPane();
root.setHgap(10);
root.setVgap(5);
for (int row = 0 ; row < 4; row++) {
for (int col = 0 ; col < 2; col++) {
root.add(new TextField(), col, row);
}
}
root.setPadding(new Insets(5));
Scene scene = new Scene(root);
scene.getStylesheets().add("style.css");
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}

产生

enter image description here

关于css - 使用 JavaFx 的文本字段 CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46812588/

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