Giter Club home page Giter Club logo

javafx-observables-tasks's Introduction

โšก JavaFX Observables Tasks

  • Java code to display list of employees when button pressed in FXML controller gridpane
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

๐Ÿ“„ Table of contents

๐Ÿ“š General info

  • Code from Java Programming Masterclass Section 15-285 JavaFx background tasks in Java - see ๐Ÿ‘ Inspiration below
  • Progress bar shown below list with text detail of data added using simple for loop
  • Employee Service now separated
  • Progress bar and Progress label binding to

๐Ÿ“ท Screenshots

N/A

๐Ÿ“ถ Technologies

๐Ÿ’พ Setup

  • Open folder in an IDE such as IntelliJ. Run from Main.java

๐Ÿ’ป Code Examples

  • Main.java code to create a list observable then bind values to a FXML ListView
public class Controller {

  private Task<ObservableList<String>> task;

  @FXML
  private ListView listView;

  @FXML
  private ProgressBar progressBar;

  @FXML
  private Label progressLabel;

  public void initialize() {
    task = new Task<ObservableList<String>>() {
      @Override
      protected ObservableList<String> call() throws Exception {

        String[] names = {"Tim Buchalka",
                "Bill Rogers",
                "Jack Jill",
                "Joan Andrews",
                "Mary Johnson",
                "Bob McDonald"};

        ObservableList<String> employees = FXCollections.observableArrayList();

        for(int i=0; i<6; i++) {
          employees.add(names[i]);
          updateMessage(names[i] + " added to the list");
          updateProgress(i + 1, 6);
          Thread.sleep(200);
          updateMessage("list complete");
        }
        return employees;

      }
    };

    progressBar.progressProperty().bind(task.progressProperty());
    progressLabel.textProperty().bind(task.messageProperty());
    listView.itemsProperty().bind(task.valueProperty());
  }

  @FXML
  public void buttonPressed() {
    new Thread(task).start();
  }
}

๐Ÿ†’ Features

  • Progress label shows each name as it is added to the list then a 'list complete' message is displayed

๐Ÿ“‹ Status & To-Do List

  • Status: Working
  • To-Do: Nothing

๐Ÿ‘ Inspiration

๐Ÿ“ License

  • N/A

โœ‰๏ธ Contact

javafx-observables-tasks's People

Contributors

andrewjbateman avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.