JavaFX 9 Proposal: MappedList

When working with JavaFX 8 we found SortedList and FilteredList very convenient, as it is a rather daily problem we face: Customers not only want to see a list as provided by the data backend, but want to reduce the amount by masking unnecessary lines, and want to sort according to their always changing current needs. Having the sort and filter criteria bindable really makes this otherwise tedious task is real nobrainer.

But what we really miss about lists is that there is no conversion of the entries. For example, our data backend provides ObservableList but what our ListView shall show actually is just the licence tag. It is pretty annoying that one has to author a rather lot of boring source code to get that pretty simple task done!

Hence we came up with the idea of MappedList. This class follows the same idea of SortedList and FilteredList: It is a live view on an ObservableList, but it uses a customizable on-the-fly conversion. So one can simply bind a ListView to an ObservableList for example, and the only Java code needed for the conversion (thanks to Java 8 method handles) would be:

ObservableList<Car> cars = ...;
MappedList<String> licenceTags = new MappedList<>(cars, Car::getTag);

(Actually this is a bad example. I would rather map to LicenceTag instead, and use a nice LicenceTagControl to display it in cool style.)

If you like this idea, you can find a starting point at OpenJFX Ticket 8134676, and I would really love to see some votes to convince Oracle how great this idea is… 🙂

About Markus Karg

Java Guru with +30 years of experience in professional software development. I travelled the whole world of IT, starting from Sinclair's great ZX Spectrum 48K, Commodore's 4040, over S/370, PCs since legendary XT, CP/M, VM/ESA, DOS, Windows (remember 3.1?), OS/2 WARP, Linux to Android and iOS... and still coding is my passion, and Java is my favourite drug!
This entry was posted in Java, Open Source, Programming, Projects, Standards and tagged . Bookmark the permalink.