当前位置: 首页 > 知识库问答 >
问题:

如何改变对话框/窗口标题的颜色?

高嘉熙
2023-03-14
/*
.root {     
-fx-text-base-color: blue;
-fx-text-background-color: green;
-fx-text-inner-color: red;
-fx-selection-bar-text: yellow;
}
*/
package de.test.dialog;

import java.io.IOException;

import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;


public class Dialog extends Stage {

public static final String OK_DIALOG = "OK";

private final String OK_XML = "/fxml/dialog_ok.fxml";


public enum DIALOG_ACTION {
    BUTTON_1, BUTTON_2, BUTTON_3, NOTHING, CLOSE_WINDOW
}

private DialogController controller = null;
private String message = null;


public Dialog(String name, String ... buttonName) {     
    String resource = getFXMLResource(name);
    if (resource != null) {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(resource));
            Parent root = (Parent) fxmlLoader.load();
            controller = fxmlLoader.getController();
            controller.setButtons(buttonName);
            setScene(new Scene(root));
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            System.out.println("Closing?");             
        }
    });
}

private String getFXMLResource(String name) {
    String fxmlResource = null;

    switch(name) {
        case OK_DIALOG:
            fxmlResource = OK_XML;
            break;
        default:
            break;
    }

    return fxmlResource;
}

public Dialog.DIALOG_ACTION getAction() {
    if (controller != null) {
        return controller.getAction();
    }
    else {
        return DIALOG_ACTION.NOTHING;
    }
}

public void setMessage(String sMessage) {
    this.message = sMessage;
    if (controller != null) {
        controller.setMessage(message);
    }
}

public void setIcon(Image image) {      
    if (controller != null) {
        controller.setIcon(image);
    }       
}
}
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="176.0" prefWidth="400.0" stylesheets="@styles/dialog.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.dialog.DialogController">
   <children>
  <ImageView fx:id="imgIcon" fitHeight="48.0" fitWidth="48.0" layoutX="8.0" layoutY="25.0" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="15.0" AnchorPane.topAnchor="25.0">
     <image>
        <Image url="@../icons/dialog/48a.png" />
     </image>
  </ImageView>
  <Text fx:id="txtMessage" layoutX="85.0" layoutY="45.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TEST" wrappingWidth="300.00" AnchorPane.leftAnchor="94.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="25.0">
     <font>
        <Font size="14.0" />
     </font>
  </Text>
  <Button fx:id="btn1" defaultButton="true" layoutX="295.0" layoutY="134.0" mnemonicParsing="false" onAction="#doAction" prefHeight="25.0" prefWidth="90.0" text="OK" AnchorPane.rightAnchor="15.0">
     <font>
        <Font size="14.0" />
     </font>
  </Button>
  <Button fx:id="btn2" cancelButton="true" layoutX="180.0" layoutY="134.0" mnemonicParsing="false" onAction="#doAction" prefHeight="25.0" prefWidth="90.0" text="Abbrechen" visible="false" AnchorPane.rightAnchor="120.0">
     <font>
        <Font size="14.0" />
     </font>
  </Button>
  <Button fx:id="btn3" layoutX="102.0" layoutY="134.0" mnemonicParsing="false" onAction="#doAction" prefHeight="25.0" prefWidth="90.0" text="Button 3" visible="false" AnchorPane.rightAnchor="225.0">
     <font>
        <Font size="14.0" />
     </font>
  </Button>
   </children>
</AnchorPane>
    Dialog dialog = new Dialog(Dialog.OK_DIALOG, "Löschen", "Abbrechen");
    dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.initOwner(((Node)e.getSource()).getScene().getWindow());
    dialog.setResizable(false);
    dialog.setTitle("Dateianhang löschen");     
    dialog.setMessage("Wollen Sie die ausgewählte(n) Datei(en) wirklich löschen?");

    // Get the Stage.
    //Stage stage = (Stage) dialog.getScene().getWindow();
    // Add a custom icon.
    //stage.getIcons().add(new Image("/icons/dialog/48a.png"));

    dialog.showAndWait();

你好,汤姆

暂时还没有答案

 类似资料:
  • 我有一个按钮,当点击它打开一个对话框与信息从我的SQLite数据库。我已经想出了如何改变背景颜色和文本的颜色,但我有麻烦得到标题文本颜色集。我也想知道是否有可能把一个按钮放在对话框标题的一个角落里?我想把关闭按钮放在那里。 下面是设置对话框的onClickHelp按钮的代码

  • 是否可以更改Android5.0的datepicker(以及timepicker)配色方案? 我尝试过设置重音颜色,但这都不起作用(使用):

  • 有没有一种方法可以改变所有出现在Android应用程序中的警报对话框?我还想更改系统生成的对话框(比如当长时间点击任何EditText时打开的编辑文本对话框)。我想改变我应用程序中所有对话框的标题、字体、颜色和大小。 编辑 我不会从代码中调用对话框。它只是当您长时间单击任何EditText时出现的默认对话框。一般包含选择单词、全部选择、输入法等键盘选项。

  • 我需要更改Jdialog box标题栏图标。默认情况下,它使用Java咖啡图像。 我在网上查了一下,用了很多代码 没有什么能正常工作。请你帮帮我..提前致谢

  • 我正在创建一个警报对话框,上面有两个多选项,我想更改复选框的颜色以更好地适应我的应用程序的主题。这是一张照片: 您可以看到多选项项的默认绿色,而我的EditText具有正确的重音颜色。下面是我创建对话框的代码: 这是我设置布局的XML文件(order\u drink\u dialog.XML): 我在网上进行了广泛的搜索,我所能找到的只是人们使用类似和这样的替代方案,但没有一个提供我想要的外观或适