Displaying status information

Database application development is a feature of JBuilder Professional and Enterprise. Distributed application development is a feature of JBuilder Enterprise.

Many data applications provide status information about the data in addition to displaying the data itself. For example, a particular area of a window often contains information on the current row position, error messages, and other similar information. dbSwing includes a JdbStatusLabel component which provides a mechanism for such status information. It has a text property that allows you to assign a text string to be displayed in the JdbStatusLabel. This string overwrites the existing contents of the JdbStatusLabel and is overwritten itself when the next string is written to the JdbStatusLabel.

The JdbStatusLabel component automatically connects to whichever DataSet has focus. The JdbStatusLabel component doesn't display the data from the DataSet but displays the following status information generated by the DataSet:

Building an application with a JdbStatusLabel component

This section serves both as general step-by-step instructions for your real-world application, and as a tutorial with sample code and data.

To add the JdbStatusLabel to the UI of your existing application:

  1. Open the project files for the application to which you want to add a JdbStatusLabel. This application should include a JdbTable component, a Database component, and a QueryDataSet component. If you do not have such an application, use the files created for the "Retrieving data for the tutorials" topic.

    Make sure the layout for the project's contentPane is set to null.

  2. Double-click the Frame file in the project pane of the AppBrowser to open it in the content pane, then click the Design tab that appears at the bottom of the AppBrowser.

  3. Click the dbSwing tab of the component palette and click the JdbStatusLabel component.

  4. Draw the JdbStatusLabel below the JdbTable component. jdbStatusLabel1 component automatically connects to whichever DataSet object has focus.

    You typically use a JdbStatusLabel component in conjunction with another UI component, usually a JdbTable that displays the data from the DataSet. This sets both components to track the same DataSet and is often referred to as a shared cursor.

    Once the JdbStatusLabel is added, you'll notice that the JdbStatusLabel component displays information that the cursor is on Row 1 of x (where x is the number of records in the DataSet).

  5. Double-click the QueryDataSet. This displays the Column designer. Select the Last_Name and First_Name columns and set the required property to true for both in the Inspector. Set the SALARY column's min property to 25000.

  6. Run the application.

Running the JdbStatusLabel application

When you run the application, you'll notice that when you navigate the data set, the row indicator updates to reflect the current row position. Similarly, as you add or delete rows of data, the row count is updated simultaneously as well.

To test its display of validation information:

  1. Insert a new row of data. Attempt to post this row without having entered a value for the FIRST_NAME or LAST_NAME columns. A message displays in the JdbStatusLabel indicating that the row cannot be posted due to invalid or missing field values.
  2. Enter a value for the FIRST_NAME and LAST_NAME columns. Enter a number in the SALARY column (1000) that doesn't meet the minimum value. When you attempt to move off the row, the JdbStatusLabel displays the same message that the row cannot be posted due to invalid or missing field values.

By setting the text of the JdbStatusLabel at relevant points in your program programmatically, you can overwrite the current message displayed in the JdbStatusLabel with your specified text. This text message, in turn, gets overwritten when the next text is set or when the next DataSet status message is generated. The status message can result from a navigation through the data in the table, validation errors when editing data, and so on.