Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更改控件FX PopOver标题的颜色_Java_Css_Javafx_Popover_Controlsfx - Fatal编程技术网

Java 更改控件FX PopOver标题的颜色

Java 更改控件FX PopOver标题的颜色,java,css,javafx,popover,controlsfx,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 Labe

要更改设置为“始终打开”的控件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如何将标题颜色更改为红色?

下面是一个非常粗略的示例,说明如何创建自己的标题。我个人会用一个
AwesomeFontFx
图标来代替按钮。我还将标题居中并添加间距。我使用
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);
   }    
}

我也遇到了同样的问题,通过查看org.controlsfx.control中的popover.css文件,我发现了这个问题

这应该可以做到:

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

您是否尝试过使用
.popover.label
而不是
.popover>.label
?你现在选择的标签是Popover的直接子项,而你的标签可能不是。我选择了,但没有乐趣。我还尝试了
.label
,但也没有给我任何帮助。我怀疑我把搜索称为标签是在偏袒我的搜索。是的,我想那是一个长期搜索,你可能已经尝试过了。您可以在java中的标签上设置一个特定的样式类,比如
label.getStyleClass().add(“popover标签”)
,而不是
.popover>.label
只需调用它
。popover标签
也可以看看这个问题,他们做的一件事是直接使用对象的类名,而不是像这样的类选择器:
Label
而不是
。Label
你能自己制作标题吗?这在技术上是一个选项,但不是我想要的。我想我可以这样做,并且有一个带有自定义关闭按钮的HBox。我希望我能用样式表完成这项工作。好吧,这是一个备份,以防你找不到其他东西。我更新了答案,让它看起来更好。我很感激。这太完美了,谢谢你指出你是如何找到它的。