2013-07-04 528 views
0

found我可以使用CSS刪除TabPane的背景。但我如何通過使用setStyle來做到這一點?如何刪除TabPane背景陰影

TabPane tabPane = new TabPane(); 
    tabPane.setStyle("-fx-effect: null;"); 

EDIT

public class clicen extends Application 
{ 


    @Override 
    public void start(Stage primaryStage) 
    { 

     final Label label = new Label("New Connection"); 
     label.setFont(new Font("Arial", 20)); 
     Stage dialog = new Stage(); 

     dialog.initModality(Modality.APPLICATION_MODAL); 
     dialog.initOwner(primaryStage); 


     GridPane gridPane = new GridPane(); 
     //gridPane.setGridLinesVisible(true); 
     gridPane.setPadding(new Insets(25)); 
     gridPane.setHgap(30); 
     gridPane.setVgap(30); 

     TabPane tabPane = new TabPane(); 

     Tab tabConn = new Tab("General"); 
     tabConn.setStyle("-fx-font-size: 12pt;"); 
     tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); 
     Tab tabConnAdv = new Tab("Advanced"); 
     tabConnAdv.setStyle("-fx-font-size: 12pt;"); 
     tabPane.getTabs().add(tabConn); 
     tabPane.getTabs().add(tabConnAdv); 

     Text ncn = new Text("New Connection Properties"); 
     ncn.setFont(new Font("Arial", 20)); 

     /// internal grid pane 

     GridPane ingridPane = new GridPane(); 
     //ingridPane.setGridLinesVisible(true); 
     ingridPane.setPadding(new Insets(25)); 
     ingridPane.setHgap(30); 
     ingridPane.setVgap(30); 

     // internal gridpane 
     Text textHost = new Text("Host"); 
     ingridPane.add(textHost, 0, 1); 
     TextField hostIn = new TextField(); 
     ingridPane.add(hostIn, 1, 1); 
     Text textUsername = new Text("Username"); 
     ingridPane.add(textUsername, 0, 2); 
     TextField usernameIn = new TextField(); 
     ingridPane.add(usernameIn, 1, 2); 
     Text taxtPassword = new Text("Password"); 
     ingridPane.add(taxtPassword, 0, 3); 
     TextField passwdIn = new TextField(); 
     ingridPane.add(passwdIn, 1, 3); 
     Text textPort = new Text("Port number"); 
     ingridPane.add(textPort, 0, 4); 
     TextField portIn = new TextField(); 
     ingridPane.add(portIn, 1, 4); 

     Button btnConnect = new Button("Connect"); 
     btnConnect.setStyle("-fx-background-color:\n" 
       + "  rgba(0,0,0,0.08),\n" 
       + "  linear-gradient(#9a9a9a, #909090),\n" 
       + "  linear-gradient(white 0%, #f3f3f3 50%, #ececec 51%, #f2f2f2 100%);\n" 
       + " -fx-background-insets: 0 0 -1 0,0,1;\n" 
       + " -fx-background-radius: 4,4,3;\n" 
       + " -fx-padding: 7 36 6 36;\n" 
       + " -fx-text-fill: #242d35;\n" 
       + " -fx-font-size: 13px;"); 

     btnConnect.setOnAction(new EventHandler<ActionEvent>() 
     { 
      @Override 
      public void handle(ActionEvent event) 
      { 
       System.exit(0); 
      } 
     }); 

     Button btnCancel = new Button("Cancel"); 
     btnCancel.setStyle("-fx-background-color:\n" 
       + "  rgba(0,0,0,0.08),\n" 
       + "  linear-gradient(#9a9a9a, #909090),\n" 
       + "  linear-gradient(white 0%, #f3f3f3 50%, #ececec 51%, #f2f2f2 100%);\n" 
       + " -fx-background-insets: 0 0 -1 0,0,1;\n" 
       + " -fx-background-radius: 4,4,3;\n" 
       + " -fx-padding: 7 36 6 36;\n" 
       + " -fx-text-fill: #242d35;\n" 
       + " -fx-font-size: 13px;"); 

     btnCancel.setOnAction(new EventHandler<ActionEvent>() 
     { 
      @Override 
      public void handle(ActionEvent event) 
      { 
       System.exit(0); 
      } 
     }); 


     tabConn.setContent(ingridPane); 

     HBox hbox = new HBox(6); 
     hbox.setSpacing(10); 
     hbox.getChildren().add(btnConnect); 
     hbox.getChildren().add(btnCancel); 
     hbox.setAlignment(Pos.CENTER); 

     gridPane.add(ncn, 0, 0); 
     gridPane.add(tabPane, 0, 1); 
     gridPane.add(hbox, 0, 2); 
     gridPane.setAlignment(Pos.CENTER); 

     Color bColor = Color.web("F5F5F5", 1.0); 
     // Stage 
     Scene scene = new Scene(gridPane, 800, 500, Color.WHITE); 
     dialog.setScene(scene); 
     dialog.setTitle("New Connection"); 
     //Image icon = new Image(getClass().getResource("/images/system-help.png").toExternalForm()); 
     //dialog.getIcons().add(icon); 
     dialog.show(); 

     tabPane.lookup(".headers-region").setStyle("-fx-effect: null;"); 
    } 
} 

我測試此代碼。它不工作。

SOLUTON

tabPane.lookup(".tab-pane .tab-header-area .tab-header-background").setStyle("-fx-background-color: yellow;"); 

回答

3

通過查找子節點,設置樣式:

primaryStage.show(); 
// after the main stage is shown 
tabPane.lookup(".headers-region").setStyle("-fx-effect: null;"); 
+0

我更新了代碼。它不工作。也許我錯過了什麼? – user1285928

+0

您的代碼也適用於JavaFX 2.2.21-b11版本。試試這個測試:'tabPane.lookup(「。headers-region」)。setStyle(「 - fx-effect:null; -fx-padding:20px; -fx-background-color:red;」);'。 –

+0

我得到了這個結果:http://s13.postimg.org/y8cw8ivzr/xxxzxz.png但是灰色背景仍然沒有被刪除。 – user1285928

8

有中,你可以使用該TabPane一個內置的樣式類。

tabPane.getStyleClass().add("floating"); 

您可以在場景生成器

檢查

Floating style class

而結果會是這樣的:

floating tabs

希望它能幫助。

+0

非常感謝您提供的信息。這是唯一的替代風格嗎? – user1285928

+0

就我所知,這是標籤唯一的樣式。那麼這個和默認的一個。 –