GithubHelp home page GithubHelp logo

dustinkredmond / javafxtablemapper Goto Github PK

View Code? Open in Web Editor NEW
10.0 6.0 2.0 55 KB

Eliminates boilerplate code associated with creating and filling JavaFX TableViews.

License: GNU General Public License v3.0

Java 100.00%
hacktoberfest javafx

javafxtablemapper's Introduction

JavaFXTableMapper

Simply use ObjectTableView in place of JavaFX's TableView and all of the work is handled for you.

Example:

Model class:

public class Test {

  private int id;
  private String name;
  private String city;
  private String country;
  
  // annotate with HiddenField to skip rendering in TableView
  @HiddenField
  private String internalId;
  
  // annotate with ColumnName to provide custom name for the TableView
  @ColumnName(name = "Pretty Column Name")
  private String someThingLongAndUnintuitive;
  
  // getters/setters/constructor here
  // a findAll() method implementation
}

JavaFX Application:

import com.jfxdev.ObjectTableView; // our only class

ObservableList<Test> myObjects = Test.findAll();

// ObjectTableView takes care of mapping the object to a TableView
ObjectTableView<Test> table = new ObjectTableView<>(myObjects);

// use below constructor if we don't have our data yet, but still want the TableView
// ObjectTableView<Test> table = new ObjectTableView<>(Test.class); 
    
// Name multiple columns via Map
HashMap<String,String> columnNames = new HashMap<>();
columnNames.put("id", "T1_ID");
columnNames.put("name", "NAME");
table.applyColumnNameMapping(columnNames);

// or name them one at a time (a bit slower)
table.renameColumn("city", "City");

If we add the above ObjectTableView to a scene, we should end up with the following:

table

That's all folks, everything is handled in the com.jfxdev.ObjectTableView class. Feel free to use it in your own code or fork the repo.

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.