I am having trouble making it so that my nameInput
label and passInput
label are bolded. My program allows me to do a -fx-text-fill: #FFFFFF;
and that works but when i try -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:
.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!
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.