JavaFX2:不能在窗格上混合一些 "setStyle"

JavaFX2 : can not mix some "setStyle" on Pane

描述

在 windows7 和 JDK1.8.0_20 上,我只是尝试显示一些带有黑色边框和给定背景颜色的窗格。为此,我使用 "setStyle" 方法,并使用以下文档 http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#region。问题代码在 TestPane class 中。 请参阅下面的完整 运行 代码:

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));
    }
}
}

经过一些尝试,我不能混合这段代码:

        // 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

最后一个好像接替了第一个不显示了。第一张图是背景线前的边框线组,第二张图是边框线前的背景线组。

问题

如何同时显示两种风格? 干杯,

杰克斯

setStyle() 是一个 setter 方法,因此它不会追加..

您想将所有样式合并为一个String:

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