Skip to content

Instantly share code, notes, and snippets.

@CalebWhiting
Created August 23, 2016 12:37
Show Gist options
  • Save CalebWhiting/85bbfb5610c1a01d4dcf0b52e943feed to your computer and use it in GitHub Desktop.
Save CalebWhiting/85bbfb5610c1a01d4dcf0b52e943feed to your computer and use it in GitHub Desktop.
package demo;
import com.javaface.javafx.JavafaceScene;
import com.javaface.javafx.style.metal.MetalLightStyle;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import java.util.Collections;
/**
* Project: Javaface
*
* @author Caleb Whiting
*/
public class UIDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
TableView<Person> table = createTable();
Label header = new Label("Demo UI");
header.setStyle("-fx-font-size: 32px;");
Button exit = new Button("Exit");
exit.setOnAction(evt -> System.exit(0));
HBox bottom = new HBox(exit);
bottom.setStyle("-fx-padding: 5px 0 0 0;");
BorderPane content = new BorderPane(table, header, null, bottom, null);
JavafaceScene scene = new JavafaceScene(content);
scene.init(new MetalLightStyle());
// if the style isn't undecorated the custom title-bar isn't visible
stage.initStyle(StageStyle.UNDECORATED);
stage.setTitle("Demo");
stage.setScene(scene);
stage.show();
}
private TableView<Person> createTable() {
TableView<Person> characters = new TableView<>();
TableColumn<Person, String> name = new TableColumn<>("Name");
TableColumn<Person, String> job = new TableColumn<>("Job");
name.setCellValueFactory(cell -> cell.getValue().name);
job.setCellValueFactory(cell -> cell.getValue().job);
Collections.addAll(characters.getColumns(), name, job);
characters.getItems().addAll(
new Person("James Kirk", "Captain"),
new Person("Mr. Spock", "Science Officer"),
new Person("Leonard McCoy ", "Doctor"),
new Person("Montgomery Scott", "Chief Engineer")
);
return characters;
}
private static class Person {
@FXML
final SimpleStringProperty name;
@FXML
final SimpleStringProperty job;
Person(String name, String job) {
this.name = new SimpleStringProperty(name);
this.job = new SimpleStringProperty(job);
}
}
public static void main(String[] args) {
Application.launch(UIDemo.class, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment