2015-04-14 63 views
0

說明JavaFX2:不能窗格

Windows7上,並用JDK1.8.0_20混合一些「的setStyle」,我只是嘗試用一個黑色的邊框,並用給定的背景顏色來顯示一些窗格。我正在使用「setStyle」方法,並使用以下文檔http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#region。問題代碼在TestPane類中。 請參見下面的完整運行代碼:這一個

 // first style part - start 
     this.setStyle("-fx-border-color: #FFFFFF;"); 
     this.setStyle("-fx-border-width: 1px;"); 
     this.setStyle("-fx-border-style: solid;"); 
     // first style part - end 

package pane; 

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.paint.Color; 
import javafx.scene.text.Text; 
import javafx.stage.Stage; 

public class BorderPaneApp extends Application { 

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

@Override 
public void start(Stage primaryStage) { 
    primaryStage.setTitle("BorderPane"); 

    MainPane mainPane = new MainPane(); 

    Scene scene = new Scene(mainPane, 400, 300, Color.ORANGE); 

    // do it for the layout 
    mainPane.prefHeightProperty().bind(scene.heightProperty()); 
    mainPane.prefWidthProperty().bind(scene.widthProperty()); 

    primaryStage.setScene(scene); 
    primaryStage.show(); 

} 


public class MainPane extends BorderPane{ 
    public TestPane topPane = new TestPane("top", Color.LIGHTSKYBLUE); 
    public TestPane leftPane = new TestPane("left", Color.AQUA); 
    public TestPane bottomPane = new TestPane("bottom", Color.AZURE); 
    public TestPane centerPane = new TestPane("center", Color.LIGHTBLUE); 

    public MainPane(){ 
     this.setTop(this.topPane); 
     this.setLeft(this.leftPane); 
     this.setCenter(this.centerPane); 
     this.setBottom(this.bottomPane); 
    } 
} 

public class TestPane extends BorderPane { 
    public TestPane(String name, Color color){ 

     // first style part - start 
     this.setStyle("-fx-border-color: #FFFFFF;"); 
     this.setStyle("-fx-border-width: 1px;"); 
     this.setStyle("-fx-border-style: solid;"); 
     // first style part - end 

     // second style part - start 
     this.setStyle("-fx-background-color: " + color.toString().replace("0x", "#") + ";"); 
     // second style part - end 

     this.setCenter(new Text(name)); 
    } 
} 
} 

一些嘗試後,我不能混用這個代碼

 // second style part - start 
     this.setStyle("-fx-background-color: " + color.toString().replace("0x", "#") + ";"); 
     // second style part - end 

最後一個似乎採取在第一個,不顯示它。第一張照片顯示背景之前的邊框線集,第二張顯示邊框線之前的背景集。

enter image description here enter image description here

問題

如何同時顯示風格一起? 乾杯,

Jakez

回答

1

setStyle()二傳手方法,因此不追加..

你想要的所有樣式組合成一個String

setStyle("-fx-border-color: #FFFFFF;-fx-border-width: 1px;-fx-border-style: solid;-fx-background-color: " + color.toString().replace("0x", "#") + ";"); 
+0

謝謝,我被錯誤地解釋爲風格是一種關鍵的機械主義價值。感謝您的快速和明確的答案。 – Jakez