我正在尝试使用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;
}
Run Code Online (Sandbox Code Playgroud)
我已经研究过这个问题了,但是我找到类似的答案并没有真正包含足够的信息来重现并适用于我的程序.我对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 ;
}
Run Code Online (Sandbox Code Playgroud)
以下测试工具
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);
}
}
Run Code Online (Sandbox Code Playgroud)
产生
因为你只想要一个下划线,所以你需要的最少的东西是
.text-field {
-fx-border-color: grey;
-fx-border width: 0 0 1 0; // top, right, bottom, left
-fx-background-color: transparent;
}
Run Code Online (Sandbox Code Playgroud)
这会将边框颜色更改为灰色,将除底部边框以外的所有内容的边框宽度设置为 0,并将文本字段的背景设置为透明,使其不是白色。
| 归档时间: |
|
| 查看次数: |
11714 次 |
| 最近记录: |