更改控件的颜色FX PopOver标题

时间:2017-11-13 20:36:41

标签: java css javafx popover controlsfx

想要更改控件FX PopOver标题的颜色,该标题设置为始终打开。我想在CSS中这样做,我已经改变了背景颜色。我在.popover下尝试了几个不同的选项。

这是我尝试的最后一件事的CSS的例子:

public class HelloPopOver extends Application {

    @Override
    public void start(Stage primaryStage) {


        //Build PopOver look and feel
        Label lblName = new Label("John Doe");
        Label lblStreet = new Label("123 Hello Street");
        Label lblCityStateZip = new Label("MadeUpCity, XX 55555");   
        VBox vBox = new VBox(lblName, lblStreet, lblCityStateZip);
        //Create PopOver and add look and feel
        PopOver popOver = new PopOver(vBox);

        // I always want to see my header
        popOver.setHeaderAlwaysVisible(true);

        Label label = new Label("Mouse mouse over me");
        label.setOnMouseEntered(mouseEvent -> {
            popOver.show(label);
            ((Parent)popOver.getSkin().getNode()).getStylesheets().add(getClass().getResource("Style.css").toExternalForm());
        });


        StackPane root = new StackPane();
        root.getChildren().add(label);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
   }    
}

CSS:

.popover > .border {
    -fx-stroke-width: 0.5;
    -fx-fill: rgba(200,200,200, 1);
    -fx-text-fill: red; /* This doesn't work, but is what I am looking for */
}
.popover > .label {
    -fx-text-fill: red; /* This doesn't work, but is what I am looking for */
 }

CSS如何将标题颜色更改为红色?

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题并通过查看org.controlsfx.control中的popover.css文件来计算出来。

这应该可以解决问题:

.popover > .content > .title > .text  {
    -fx-text-fill: red;
}

答案 1 :(得分:0)

以下是如何创建自己的标头的一个非常粗略的示例。我个人会使用AwesomeFontFx图标代替按钮。我也会将标题居中并添加间距。我使用Text作为标题。 Text允许您更改其颜色。

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import org.controlsfx.control.PopOver;

public class HelloPopOver extends Application {

    @Override
    public void start(Stage primaryStage) {


        //Build PopOver look and feel 



        Label lblClosePopOver = new Label("x");
        Text lblHeader = new Text("Keyword info");
        lblHeader.setFill(Color.RED);
        HBox headerRoot = new HBox(lblClosePopOver, lblHeader);
        headerRoot.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
        Label lblName = new Label("John Doe");
        Label lblStreet = new Label("123 Hello Street");
        Label lblCityStateZip = new Label("MadeUpCity, XX 55555");  

        VBox infoHolder = new VBox(lblName, lblStreet, lblCityStateZip);
        VBox.setMargin(infoHolder, new Insets(7, 7, 7, 7));
        VBox subRoot = new VBox(new StackPane(headerRoot), infoHolder);
        AnchorPane popOverRoot = new AnchorPane(subRoot);


        //Create PopOver and add look and feel
         Label label = new Label("Mouse mouse over me");
        PopOver popOver = new PopOver(label);
        popOver.setContentNode(popOverRoot);
        lblClosePopOver.setOnMouseClicked((event)->{
            if(popOver.isShowing())
            {
                popOver.hide();
            }
        });
    // I always want to see my header        
    //popOver.setHeaderAlwaysVisible(true);


        label.setOnMouseEntered(mouseEvent -> {
            popOver.show(label);
        });


    StackPane root = new StackPane();
    root.getChildren().add(label);

    Scene scene = new Scene(root, 300, 250);


        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
   }    
}

enter image description here