2015-04-14 36 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