Scroll Bar
- Common Properties
- Font-specific Properties
- Other Common Properties
- Property Propagation Between Model and Control
- Common Workflow to add Controls
- The Example Listings
- Label Field
- Command Button
- Image Control
- Check Box
- Radio Button
- Scroll Bar
- List Box
- Combo Box
- Progress Bar
- Horizontal/Vertical Line Control
- Group Box
- Text Field
- Text Field Extensions
- Formatted Field
- Numeric Field
- Currency Field
- Date Field
- Time Field
- Pattern Field
- Roadmap Control
- File Control
- File Picker
- Message Box
A com.sun.star.awt.UnoControlScrollBar can be used to display arbitrary content. This can be content that is too large in size to fit into a dialog or any other measurable content. It offers assistance to the user for the navigation through a container, like a group of controls. The user positions the thumb in the scroll bar to determine which part of the content is to be displayed in the viewing area of the dialog. The component that uses the scroll bar then typically adjusts the display so that the end of the scroll bar represents the end of the contents that can be displayed, or 100%. The start of the scroll bar is the beginning of the content that can be displayed, or 0%. The position of the thumb within those bounds then translates to the corresponding percentage representing the position within the total content.
Typically a com.sun.star.awt.XAdjustmentListener is added to the control by means of the method addAdjustmentListener()
of the interface com.sun.star.awt.XScrollBar. The method adjustmentValueChanged
is called each time the position of the thumb in the scroll bar changes. The model com.sun.star.awt.UnoControlScrollBarModel offers the following properties:
Properties of com.sun.star.awt.UnoControlScrollBarModel | |
---|---|
ScrollValue | long . The ScrollValue property represents the position of the thumb.
|
LineIncrement | long . The LineIncrement property specifies the change of the scroll value per mouse click on an arrow.
|
BlockIncrement | long . The BlockIncrement property specifies the change of the Scrollvalue property when clicking in a scroll bar in the region between the thumb and and the arrows.
|
Orientation | long . Specifies the orientation of the scroll bar. Accepts either com.sun.star.awt.ScrollBarOrientation.VERTICAL or com.sun.star.awt.ScrollBarOrientation.HORIZONTAL
|
RepeatDelay | long . Specifies the delay in milliseconds between repeating events. A repeating event occurs when clicking on a button or the background of a scroll bar while keeping the mouse button pressed for some time.
|
ScrollValueMin | long . The ScrollValueMin property defines the minimum value of the Scrollvalue property.
|
ScrollValueMax | long . The ScrollValueMax property defines the maximum value of the Scrollvalue property.
|
VisibleSize | long . The property VisibleSize defines the visible size of the thumb and represents the percentage of the currently visible content and the total content that can be displayed.
|
You can also set these attributes com.sun.star.awt.XScrollBar interface.
This example demonstrates how you can set up a scroll bar:
public XPropertySet insertVerticalScrollBar(XAdjustmentListener _xAdjustmentListener, int _nPosX, int _nPosY, int _nHeight){ XPropertySet xSBModelPSet = null; try{ // create a unique name by means of an own implementation... String sName = createUniqueName(m_xDlgModelNameContainer, "ScrollBar"); Integer NOrientation = new Integer(com.sun.star.awt.ScrollBarOrientation.VERTICAL); // create a controlmodel at the multiservicefactory of the dialog model... Object oSBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlScrollBarModel"); XMultiPropertySet xSBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oSBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xSBModelMPSet.setPropertyValues( new String[] {"Height", "Name", "Orientation", "PositionX", "PositionY", "Width"}, new Object[] { new Integer(_nHeight), sName, NOrientation, new Integer(_nPosX), new Integer(_nPosY), new Integer(8)}); // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oSBModel); xSBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oSBModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration xSBModelPSet.setPropertyValue("ScrollValueMin", new Integer(0)); xSBModelPSet.setPropertyValue("ScrollValueMax", new Integer(100)); xSBModelPSet.setPropertyValue("ScrollValue", new Integer(5)); xSBModelPSet.setPropertyValue("LineIncrement", new Integer(2)); xSBModelPSet.setPropertyValue("BlockIncrement", new Integer(10)); // Add an Adjustment that will listen to changes of the scrollbar... XControl xSBControl = m_xDlgContainer.getControl(sName); XScrollBar xScrollBar = (XScrollBar) UnoRuntime.queryInterface(XScrollBar.class, xSBControl); xScrollBar.addAdjustmentListener(_xAdjustmentListener); }catch (com.sun.star.uno.Exception ex){ /* perform individual exception handling here. * Possible exception types are: * com.sun.star.lang.IllegalArgumentException, * com.sun.star.lang.WrappedTargetException, * com.sun.star.container.ElementExistException, * com.sun.star.beans.PropertyVetoException, * com.sun.star.beans.UnknownPropertyException, * com.sun.star.uno.Exception */ ex.printStackTrace(System.out); } return xSBModelPSet; }
The adjustmentListener
, that has been added to the example scroll bar must implement the method adjustmentValueChanged()
:
public void adjustmentValueChanged(AdjustmentEvent _adjustmentEvent) { switch (_adjustmentEvent.Type.getValue()){ case AdjustmentType.ADJUST_ABS_value: System.out.println( "The event has been triggered by dragging the thumb..." ); break; case AdjustmentType.ADJUST_LINE_value: System.out.println( "The event has been triggered by a single line move.." ); break; case AdjustmentType.ADJUST_PAGE_value: System.out.println( "The event has been triggered by a block move..." ); break; } System.out.println( "The value of the scrollbar is: " + _adjustmentEvent.Value); }
Content on this page is licensed under the Public Documentation License (PDL). |