Skip to content

Instantly share code, notes, and snippets.

@fabianbaechli
Last active November 23, 2017 14:46
Show Gist options
  • Save fabianbaechli/ccc363fdff730c65e813bcffa0d107f2 to your computer and use it in GitHub Desktop.
Save fabianbaechli/ccc363fdff730c65e813bcffa0d107f2 to your computer and use it in GitHub Desktop.

Präsentation JavaFx

Setup Process

  1. Herunterladen von Gluon scene-builder
  2. Installieren von e(fx)clipse in eclipse
  3. Window -> Preferences -> JavaFx -> Scene Builder path setzen
  4. Main.java
package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {
 public static void main(String[] args) {
   launch(args);
}

 @Override
 public void start(Stage stage) throws Exception {
   Parent root = FXMLLoader.load(getClass().getResource("HelloWorld.fxml"));

   Scene scene = new Scene(root);
   stage.setTitle("Hello World");
   stage.setScene(scene);
   stage.show();
 }
}
  1. MainStageController.java
package application;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
public class MainStageController {
  @FXML
  Button myButton;

  @FXML
  TextField myTextField;

  public void initialize() {
    myButton.setOnAction(e -> {
      myTextField.setText("hello world");
    });
  }
}
  1. HelloWorld.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>

<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="259.0" prefWidth="425.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainStageController">
   <children>
      <AnchorPane prefHeight="208.0" prefWidth="600.0">
         <children>
            <Button fx:id="myButton" alignment="BOTTOM_LEFT" layoutX="171.0" layoutY="220.0" mnemonicParsing="false" text="Hello World!" />
            <TextField fx:id="myTextField" editable="false" layoutX="138.0" layoutY="117.0" />
         </children>
      </AnchorPane>
   </children>
</StackPane>

Ressourcen

Libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment