The Legend panel bean is represented by the IlvMapLegendPanel class. This bean enables
users to create a legend to define map elements.
An example of the Legend panel bean is shown in Legend panel bean .
![legendpanel.png](../usrprgmaps/_media/legendpanel_default.png)
Legend panel bean
Including the bean in an application
To include the Legend panel bean in your
application, write the following lines of code:
IlvMapLegendPanel legend = new IlvMapLegendPanel(); legend.setView(view);
Adding the bean to a Swing container
You can then add this bean into the Swing
hierarchy of your application:
panel.add(legend, BorderLayout.EAST);
The Legend panel bean then attaches itself and listens to the IlvMapLayerTreeProperty property of the
manager of the view. Whenever a layer is changed in the
underlying IlvMapLayerTreeModel, the legend updates
itself.
Customizing the appearance and behavior
If you do not want an automatic
JScrollPane
around your legend, you can use:
IlvMapLegend legend = new IlvMapLegend (); legend.setView(view);
The Legend panel uses the properties of maplayers to retrieve the
IlvMapStyle.CATEGORY
and
IlvMapStyle.LEGEND_GROUP
string properties (for details of these properties, see Common styling properties).
By default (when these values are null), each map layer has its
own line in the legend. The user can override this by setting
identical values in the
Category
or
Legend Group
fields.
Layers are ordered according to their
legend group (all layers with the same legend group are displayed
together, inside the same frame).
When layers share the same legend group and
category, they are displayed on a single legend line – possibly
with more than one legend caption to display all the different
aspects this legend item can have.