Reputation: 59
Is there any way to remove this white space that appears under a Button when it is not in focus?
This button has had its appearance changed with the use of JavaFX CSS however unfocused Buttons seem to have this by default when customised or uncustomised. Has anyone been able to resolve this as it hinders appearance when on a different colour background.
Tried changing the focus appearance using CSS but the issue arises when the button is out of focus.
Minimal Code to produce this issue:
package com.example.buttonexample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Button button1 = new Button("Login");
Button button2 = new Button("Sign Up");
HBox root = new HBox();
root.setStyle("-fx-background-color: orange");
button1.setPrefHeight(50);
button2.setPrefHeight(50);
root.getChildren().addAll(button1, button2);
Scene newScene = new Scene(root);
stage.setWidth(200);
stage.setHeight(200);
stage.setScene(newScene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Running:
Found the solution: Add this to the CSS -fx-background-insets: 0,1,1; Or set the insets through the method.
Upvotes: 3
Views: 79
Reputation: 59
Answer: Remove the insets that are placed on the default button using -fx-background-insets: 0; or the corresponding method.
Upvotes: 2