2015-06-01 103 views
0

請考慮將示例程序添加到警報中的示例程序。正如你將看到的,TabPane左側有一個白色填充,我無法刪除。刪除警報的左側填充

如果有人有任何想法,這將是偉大的。

代碼:

import javafx.application.Application; 
import javafx.geometry.Insets; 
import javafx.scene.Scene; 
import javafx.scene.control.Alert; 
import javafx.scene.control.Tab; 
import javafx.scene.control.TabPane; 
import javafx.scene.layout.HBox; 
import javafx.stage.Stage; 

public class AlertTest extends Application { 

    public static void main(String[] args) { 
     launch(args); 
    } 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
     Scene scene = new Scene(new HBox()); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 

     Alert alert = new Alert(Alert.AlertType.NONE); 
     alert.setTitle(""); 
     alert.initOwner(primaryStage); 
     TabPane tabPane = new TabPane(new Tab("test")); 
     tabPane.setPadding(Insets.EMPTY); 
     alert.getDialogPane().setPadding(Insets.EMPTY); 
     alert.getDialogPane().setContent(tabPane); 
     alert.show(); 
    } 
} 

視覺: Ugly left padding

回答

1

如果添加CSS是這樣的:

public void start(Stage primaryStage) throws Exception { 
    Scene scene = new Scene(new HBox()); 
    primaryStage.setScene(scene); 

    //add this 3 lines 
    String css = Main.class.getResource("styles.css").toExternalForm(); 
    scene.getStylesheets().clear(); 
    scene.getStylesheets().add(css); 

    ... 
} 

和Styles.css中添加

.dialog-pane:no-header .graphic-container { 
    -fx-padding: 0; /* 10px 0px 0px 10px */ 
} 

您可以找到有關文件的默認樣式的更多信息:fxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.css

,這裏是結果,full code demo

enter image description here

+0

這是一個有點哈克但工作完美:) 謝謝 – Maxoudela