I have a treetableview which multiple columns. I like to order only by one column so I apply:
treetbvItems.getSortOrder().add("categoria");
This order data by column "categoria" alphabetical but I want to apply my custom order.
For example, if category can be onew of this values: animals, computers, shoes, vehicles... with above sentence, I get tree order by this way:
- animals
- computers
- shoes
- vehicles
but if I want (can be any other custom orther):
- computers
- shoes
- animals
- vehicles
Is possible or not to do whith JavaFX?
I assume you really mean
since the code you posted won't compile.
You can control the ordering for a particular column by setting a
Comparator
on the column.The
Comparator
defines acompareTo(String, String)
method that returns an negativeint
if the first argument comes before the second, a positiveint
if the second argument comes before the first, and 0 if they are equal.So you could do something like:
Note that if you have a fixed set of categories, you should probably use an
Enum
instead of aString
. The "natural" order of anEnum
is defined by its declaration order.