如何在javaFX中更改舞台框架的颜色?

时间:2016-10-09 08:26:20

标签: java css javafx

标题很直接。有没有办法做到这一点?默认为白色,但它与我的应用程序颜色方案冲突。我的目标是像Spotify这样的窗口

窗口上我的意思是整个画面,看看左上角的图标如何有spotify标识,背后的背景是彩色的?左侧的窗口控件也是如此。

enter image description here

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

尝试使用css:

.menu-bar {
  -fx-background-color: derive(#FF1d1d,20%); // your color here
}

布局示例:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.input.*?>
<?import javafx.scene.layout.*?>

<BorderPane prefHeight="400.0" prefWidth="700.0" stylesheets="@DarkTheme.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.makery.address.view.RootLayoutController">
<top><MenuBar BorderPane.alignment="CENTER">
  <menus>
    <Menu mnemonicParsing="false" text="File">
      <items><MenuItem mnemonicParsing="false" onAction="#handleNew" text="New">
<accelerator>
<KeyCodeCombination alt="UP" code="N" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem><MenuItem mnemonicParsing="false" onAction="#handleOpen" text="Open...">
<accelerator>
<KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
        <MenuItem mnemonicParsing="false" onAction="#handleSave" text="Save">
<accelerator>
<KeyCodeCombination alt="UP" code="S" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
        <MenuItem mnemonicParsing="false" onAction="#handleSaveAs" text="Save As..." /><MenuItem mnemonicParsing="false" onAction="#handleExit" text="Exit" />
      </items>
    </Menu>
    <Menu mnemonicParsing="false" text="Statistics">
      <items>
        <MenuItem mnemonicParsing="false" onAction="#handleShowBirthdayStatistics" text="Show Statistics" />
      </items>
    </Menu>
    <Menu mnemonicParsing="false" text="Help">
      <items>
        <MenuItem mnemonicParsing="false" onAction="#handleAbout" text="About" />
      </items>
    </Menu>
  </menus>
</MenuBar>
</top></BorderPane>

Result