J'ai créé une boîte de dialogue personnalisée dans Javafx. Le problème auquel je fais face est que, chaque fois que j'appuie sur une touche, la taille du dialogue diminue.DialogPane personnalisé Javafx dont la couleur de la bordure se rétrécit chaque fois qu'une touche est incrustée
Le code pour la coutume de dialogue est la suivante
package javafxcustomdialog;
import java.util.List;
import java.util.Optional;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class JavafxCustomDialog extends Application {
@Override
public void start(Stage primaryStage) {
Dialog dialog = new Dialog();
DialogPane dialogPane = dialog.getDialogPane();
dialog.setHeaderText(null);
dialog.setGraphic(null);
dialog.initStyle(StageStyle.UNDECORATED);
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.getDialogPane().setStyle("-fx-background-color: #fff; -fx-border-color: #e7eaeC#e7eaeC#e7eaeC#e7eaec; -fx-border-width: 6;");
// Set the button types.
ButtonType okButtonType = new ButtonType("Ok", ButtonBar.ButtonData.OK_DONE);
ButtonType cancelButtonType = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
dialog.getDialogPane().getButtonTypes().addAll(okButtonType, cancelButtonType);
// VBox
VBox alertVBox = new VBox();
VBox.setVgrow(alertVBox, Priority.ALWAYS);
alertVBox.setPrefWidth(400.0);
alertVBox.setSpacing(10);
Label label = new Label("Enter Some Text");
TextField textField = new TextField();
alertVBox.getChildren().addAll(label, textField);
// END VBox
dialog.getDialogPane().setContent(alertVBox);
// Request focus on the username field by default.
Platform.runLater(() -> textField.requestFocus());
// result
Optional<List<String>> result = dialog.showAndWait();
if (result.isPresent()) {
System.out.println("Good");
} else {
System.out.println("Something is wrong..!!");
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Le problème est dans cette ligne
dialog.getDialogPane().setStyle("-fx-background-color: #fff; -fx-border-color: #e7eaeC#e7eaeC#e7eaeC#e7eaec; -fx-border-width: 6;");
Screenshot: