Programming with JViews Maps > Creating a Map Application Using the API > Using the GUI Beans > Scale Bar

The Scale Bar Bean is represented by the IlvJAutomaticScaleBar class. This Bean enables users to estimate distances using the displayed scale bar.

An example of the Scale Bar is shown in Figure 3.4.

scalebar.png

Figure 3.4 Scale Bar

Including the Bean in an Application

To include the Scale Bar Bean in your application, write the following lines of code:

IlvJAutomaticScaleBar graphicScale = new IlvJAutomaticScaleBar();
graphicScale.setView(view);

Adding the Bean to a Swing Container

You can then add this Bean into your Swing hierarchy.

panel.add(graphicScale, BorderLayout.SOUTH);

The Scale Bar Bean then attaches itself and listens to the IlvDisplayPreferencesProperty property of the manager of the view. Whenever the underlying IlvDisplayPreferences are changed (see Display Preferences Editor), the units used to display distances change.

You can also force the scale bar Bean to use specific units, regardless of the IlvDisplayPreferencesProperty settings, by calling the setFarUnit and setNearUnit methods in your application code.

Changing the Appearance of the Scale Bar

The following controls change the appearance of the scale bar:

graphicScale.setMarginHeight(2);
graphicScale.setMarginWidth(2);
graphicScale.setTextSpacing(2);
graphicScale.setScaleStyle(IlvScaleBar.DOUBLE_DASH_SCALE_EVEN);
graphicScale.setScaleTextMode(IlvScaleBar.THREE_LABELS);
graphicScale.setScaleHeight(10);