2015-06-01 104 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