2
Ich machte ein undekorated Fenster in JavaFX, aber dann verschwanden alle meine Komponenten.JavaFX - Undecorated Windows hat einige Probleme
Mein Code:
public class Main extends Application {
private double xOffset = 0;
private double yOffset = 0;
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setResizable(false);
root.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
primaryStage.setX(event.getScreenX() - xOffset);
primaryStage.setY(event.getScreenY() - yOffset);
}
});
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
public void init(){
}
}
und das ist mein FXML Datei:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.effect.InnerShadow?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.text.Font?>
<TitledPane animated="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="Menu" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<SplitPane dividerPositions="0.29797979797979796" prefHeight="350.0" prefWidth="600.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="338.0" prefWidth="207.0" style="-fx-background-color: #333333;">
<children>
<RadioButton fx:id="test" layoutX="10.0" layoutY="95.0" mnemonicParsing="false" text="RadioButton" textFill="WHITE">
<font>
<Font size="14.0" />
</font>
<effect>
<DropShadow color="#4a4a4a" />
</effect>
</RadioButton>
<RadioButton fx:id="startBot" layoutX="10.0" layoutY="14.0" mnemonicParsing="false" onAction="#startBot" prefHeight="37.0" prefWidth="152.0" text="Start BlackHole-Bot" textFill="WHITE">
<font>
<Font size="14.0" />
</font>
<effect>
<DropShadow color="#545353" />
</effect>
</RadioButton>
<RadioButton fx:id="startNotepad" layoutX="10.0" layoutY="51.0" mnemonicParsing="false" onAction="#startNotepad" prefHeight="32.0" prefWidth="177.0" text="Notepad" textFill="WHITE">
<font>
<Font size="14.0" />
</font>
<effect>
<DropShadow color="#4a4949" />
</effect>
</RadioButton>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="348.0" prefWidth="330.0" style="-fx-background-color: #1a1a1a;">
<children>
<Button fx:id="confirmBtn" alignment="CENTER" layoutX="163.0" layoutY="258.0" mnemonicParsing="false" onAction="#confirm" text="Confirm">
<font>
<Font size="18.0" />
</font>
<effect>
<DropShadow />
</effect>
</Button>
</children>
</AnchorPane>
</items>
</SplitPane>
</children></AnchorPane>
</content>
<effect>
<InnerShadow />
</effect>
<graphic>
<Region prefHeight="23.0" prefWidth="213.0" />
</graphic>
<font>
<Font size="24.0" />
</font>
</TitledPane>
und das ist, wie es in Szene Builder aussieht:
Danke im Voraus, um mir zu helfen: D Einen schönen Tag haben
Können Sie die FXML (und CSS, wenn Sie ein Stylesheet haben)? –
yup, warte mal –
Um. Hmm. Es hat nichts damit zu tun, dass die Bühne nicht verziert ist: Wenn ich das auszeichne, hat es dasselbe Verhalten. Wenn ich das Fenster auch in der Größe änderbar mache und es dann beim Öffnen der Größe ändere, erscheint der Inhalt .... Nicht sicher, was passiert. –