[英]Javafx CSS Some Properties Not Working
I am having trouble making it so that my nameInput
label and passInput
label are bolded. 我无法制作它,以便我的
nameInput
标签和passInput
标签以粗体显示。 My program allows me to do a -fx-text-fill: #FFFFFF;
我的程序允许我做一个
-fx-text-fill: #FFFFFF;
and that works but when i try -fx-font-weight: bold;
这工作,但当我尝试
-fx-font-weight: bold;
it wont work or bold my label when the app runs. 当应用程序运行时,它不会工作或加粗我的标签。
Here is my code containing my labels and buttons: 这是我的代码,包含我的标签和按钮:
package appGUI;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.scene.layout.GridPane;
public class Login extends Application {
Stage window;
Button loginButton;
String user = "test";
String pw = "test";
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Secret");
GridPane grid = new GridPane();
grid.setPadding(new Insets(10,10,10,10));
grid.setVgap(8);
grid.setHgap(10);
// name label
Label nameLabel = new Label("Enter your name:");
GridPane.setConstraints(nameLabel, 0, 0);
// name input
TextField nameInput = new TextField();
nameInput.setPromptText("name");
GridPane.setConstraints(nameInput, 1, 0);
// password label
Label passLabel = new Label("Enter the password:");
GridPane.setConstraints(passLabel, 0, 1);
// password input
PasswordField passInput = new PasswordField();
passInput.setPromptText("password");
GridPane.setConstraints(passInput, 1, 1);
// login button
loginButton = new Button("Enter");
GridPane.setConstraints(loginButton, 1, 2);
loginButton.setOnAction(e -> {
if(nameInput.getText().equals(user) && passInput.getText().equals(pw)) {
System.out.println("THIS WORKS. YOU FINALLY SOLVED IT!!!!");
} else {
AlertBox.display("Error: Access Denied", "Only a special person can access this app");
}
});
grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, loginButton);
Scene scene = new Scene(grid, 350, 200);
scene.getStylesheets().add("/appGUI/custom.css");
window.setScene(scene);
window.show();
}
}
And here is the .css file titled "custom.css" that works properly and does everything I wrote except for bold text: 这里是标题为“custom.css”的.css文件,它可以正常工作并完成我写的所有内容,除了粗体文本:
.root {
-fx-background-color: linear-gradient(#707070, #BABABA);
}
.label {
-fx-text-fill: #FFFFFF;
-fx-font-weight: bold;
}
.button {
-fx-background-color: linear-gradient(#00F5FF, #FFA07A);
-fx-background-radius:10;
}
I have tried almost everything and I can't seem to find the answer to what seems like a really easy problem to fix. 我已经尝试了几乎所有的东西,我似乎无法找到解决看起来很容易解决的问题的答案。 My labels just wont bold, but they'll fill with
#FFFFFF
, and i just want to know why one property works and the other one doesn't! 我的标签不会大胆,但它们会填充
#FFFFFF
,我只是想知道为什么一个属性有效而另一个属性没有!
For some strange reason the default font not necessarily supports all features. 由于某些奇怪的原因,默认字体不一定支持所有功能。
Try: 尝试:
.label {
-fx-font-family: "Helvetica";
-fx-font-weight: bold;
}
If you want to make this change application wide, add it to the scene: 如果要在应用程序范围内进行此更改,请将其添加到场景中:
.root {
-fx-font-family: "Helvetica";
}
scene.getStylesheets().add("pathTo/root.css");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.