1

I just started to use JavaFx (with FXML) and I am wondering if there is a way to personalize the way list view items are displayed in the JavaFx ListView. I would like to know if there is a similar approach to the WPF ListView.ItemTemplate for JavaFx ListView.

In WPF we can define how an item is displayed in a ListView (with the option to compose controls to get the item view)

Example:

<ListView Margin="10" Name="lvDataBinding">
                        <ListView.ItemTemplate>
                                <DataTemplate>
                                        <WrapPanel>
                                                <TextBlock Text="Name: " />
                                                <TextBlock Text="{Binding Name}" FontWeight="Bold" />
                                                <TextBlock Text=", " />
                                                <TextBlock Text="Age: " />
                                                <TextBlock Text="{Binding Age}" FontWeight="Bold" />
                                                <TextBlock Text=" (" />
                                                <TextBlock Text="{Binding Mail}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" />
                                                <TextBlock Text=")" />
                                        </WrapPanel>
                                </DataTemplate>
                        </ListView.ItemTemplate>
                </ListView>

Items for the lvDataBinding ListView are specified in the code behind code of the view.

List<User> items = new List<User>();
                        items.Add(new User() { Name = "John Doe", Age = 42 });
                        items.Add(new User() { Name = "Jane Doe", Age = 39 });
                        items.Add(new User() { Name = "Sammy Doe", Age = 13 });
                        lvDataBinding.ItemsSource = items;
Raimil Cruz
  • 109
  • 1
  • 7
  • 1
    Use a cell factory. There is an example in the [tutorial](http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/list-view.htm#CEGGEDBF). – James_D Jul 27 '15 at 02:11

1 Answers1

0

After I searched a while I found this other answer. It is possible to use CellFactory to customize how items are displayed in a JavaFx ListView, even is not the way that I was expecting.

Community
  • 1
  • 1
Raimil Cruz
  • 109
  • 1
  • 7