Using the Inspector
Overview of the Inspector
The Inspector lets you visually edit component properties and attach code to component events.
Using the Inspector, you can
- Set the initial property values for components in the container, and for the container and its layout manager (initialization code).
- Create, name, and delete methods in the container that will receive events from the component in the container (event handling code).
- Save
text
property String values to a ResourceBundle or revert a resourced String back to a String constant.
- Change the level of properties exposed in the Inspector.
- Expose a property as a class level variable, so you can change it in the Inspector.
Any changes you make in the Inspector are reflected immediately in the source code and in the UI designer.
Opening the Inspector
To display the Inspector,
- Double-click a Java file in the project pane.
- Select the Design tab at the bottom of the AppBrowser.
The Inspector is displayed at the right of the content pane which is now in design view.
Resize the Inspector by dragging the left border right or left with the mouse. To adjust the width of the Inspector's columns, drag the column divider in the border at the top of the Inspector to the right or left
Setting property values
Properties are attributes that define how a component appears and responds at runtime. In JBuilder, you set a component's initial properties during design time, and your code can change those properties at runtime.
The Properties page in the Inspector displays the properties of the selected component(s). This is where you set the property values at design time for any component in your design. By setting properties at design time, you are defining the initial state of a component when the UI is instantiated at runtime.
Note: To modify the initial property values at runtime, you can put code in the body of the methods or event handlers, which you can create on the Events page of the Inspector.
To set a component's properties at design time,
- Select a component in a designer (UI designer or menu designer) or in the component tree.
- Click the Properties tab of the Inspector.
- Select the property you want to change using the mouse or arrow keys. You may need to scroll down until the property you want is visible.
- Enter the value in the right column in one of the following ways:
- Type the string value for that property, for example a text value or a number value, when there is a text field.
- Click the arrow beside the property and choose a value from the list when the value field has a drop-down list. You can also use the Up and Down arrow keys on the keyboard to move through the list, and press Enter at the desired value.
- Click the ellipsis button
to display a property editor for that property, for example, a color or font selector. Set the values in the property editor, then choose OK, or press Enter.
Setting shared properties for multiple components
When more than one component is selected, the Inspector displays only the properties they have in common that you can edit. When the value for the shared property differs among the selected components, the property value displayed is either the default or the value of the first component selected. When you change any of the shared properties in the Inspector, the property value changes to the new value in all the selected components.
To set properties for multiple components,
- Do one of the following to select the group of components to be changed:
- Hold down the Ctrl key and select each of the components in the UI designer or the component tree.
- Hold down the left mouse button and draw a rectangle around the group of components you want to change.
- Select and edit the desired property in the Inspector.
Setting a property when the drop-down list is empty
Sometimes, when you try to set a property in the Inspector (such as Swing models), all you see in the value's drop-down list is <none>
.
When no property editor is specified for a property in the bean's BeanInfo class (or if the bean does not have a BeanInfo class), the Inspector uses a default editor based on the property value's data type. If a property takes a String, for example, the editor for that property lets you type in your string.
The list of property editors by type is stored in propertyEditors.properties
in the .jbuilder
folder. If no default editor is registered for a particular data type, JBuilder builds a drop-down list containing all objects of the correct data type that are in scope (objects that have instances in the object you are designing). If there are no objects of the correct data type in scope, then the drop-down list will be empty.
For example, a JTable
has a model
property that takes objects of type TableModel. If you add a JTable
to your design in the UI designer, then click the drop-down arrow on its model
property in the Inspector, the drop-down list value is <none>
.
Note: To make the model
property visible in the Inspector, right-click in the Inspector and choose Property Exposure Level|Hidden.
To populate the model
property drop-down list in the Inspector, add objects of type TableModel to your class.
In this case, you can add a TableModel
class from the javax.swing.table
package to the design from the component palette as explained in the following steps.
Adding or Removing String values from ResourceBundle files
This is a feature of JBuilder Professional and Enterprise.
You can use the Inspector to remove a property's String value from a ResourceBundle file after you've resourced your project, or you can add a String value to a new or existing ResourceBundle file.
Right-click a property that takes a String value and choose ResourceBundle. The Localizable Property Setting dialog appears.
To remove a resourced String from a ResourceBundle,
- Select the ResourceBundle name from the list.
- Select Store Text As String Constant to remove a resourced String from its resource file.
To add a String value to a new or existing ResourceBundle,
- Select Store Text In ResourceBundle For Localization.
- Select the ResourceBundle file name to use, or click New to create a new one.
- Select the ResourceBundle type and click OK.
Important: If you remove a resourced component from the UI, it is not automatically removed from its resource file, in case the key is used somewhere else in your code. You must open the resource file and manually remove the entry.
For information on resourcing and international enablement, see Developing International Programs and the Resource wizard.
Setting the Property Exposure Level
You can choose what level of properties are exposed for the component in the Inspector based on how the properties are marked in the BeanInfo
class for the component. Right-click in the Inspector and choose Property Exposure Level to display a pop-up menu with three choices:
- Regular
-
The Inspector displays only the properties that are not marked "Hidden" or "Expert" in the component's BeanInfo class.
- Hidden
-
The Inspector displays only the properties marked "Hidden" in the component's BeanInfo class.
- Expert
-
The Inspector displays the properties marked "Expert" in the component's BeanInfo class, plus everything displayed in "Regular".
Note: Properties not exposed in the BeanInfo Class remain hidden. The designer does not know about them unless a property setting for one was found in the JbInit()
method, in which case they appear in the Inspector.
Exposing a property as a class level variable
You can use the Inspector to expose a property as a class level variable so you can set properties and events for it. For example, the jTextArea
component has a document
property that has a value of <none>
. To expose it as a class level variable, right-click the document
property and choose Expose As Class Level Variable. A variable called document1
is added to the list of class variables in the source code and the document
property now shows a value of document1
.
JBuilder also adds document1
to the Other
folder in the component tree and exposes its properties and events in the Inspector. Now you can select document1
and create event handlers for it from the Events tab.