Text boxes
Similar to a word processing document, a text box is an object that holds text (a single character, a single word, entire sentences, or paragraphs). Editing in a text box is just like working in a word processor. You can cut, copy and paste selected text easily, and format the text as needed. In addition, a text box can hold other components.
Inserting a text box into a report
A text box can be inserted in the report areas listed in Component placement.
To insert a text box into a report, use either of the following ways:
- Using menu/toolbar command
Click Insert > Text Box on the menu bar, or the Insert Text Box button on the Insert toolbar. If the mouse pointer is in the report body or a tabular cell, a text box will be inserted there upon finishing. Otherwise, you need to click the mouse button in the desired location to place the text box there.
- By dragging and dropping
From the Toolbox panel, drag Text Box to the desired location in the report which allows the insertion of a text box, and a text box will then be created.
After a text box has been inserted into a report, you can double-click it to input text. You can also customize its appearance and behavior by setting properties in the Report Inspector, which can be saved as a CSS style for future use (for details, see Creating a CSS style).
Formatting paragraphs in a text box
Paragraphs are created when text is entered into a text box. In JReport, you can easily format the paragraphs, for example, the alignment style, indentation format or line spacing. To do this:
- Right-click anywhere in the paragraph and click Paragraph on the shortcut menu.
- In the Paragraph tab of the Format Text dialog,
- To specify the alignment style of the paragraph, select the required option from the Alignment drop-down list: left, center, right or justified.
- To set the indentation formats of the paragraph, in the Indentation box, specify the left and right indent distance in the Left and Right fields. If you want to set the paragraph to be indented, select first line or hanging from the Special drop-down list, then input a number in the By text box. This will create a first-line indent or hanging indent in the paragraph using the inputted number as the indent distance.
- To adjust the spacing before or after the paragraph, enter the required amount of spacing in the Before or After field.
- To change the spacing between the lines in the paragraph, select the required item from the Line Spacing drop-down list. If at least, exactly or multiple is selected, enter the required amount of space or the number of lines in the At box.
- When done, click OK to accept the changes.
You can also set the indentation formats of a paragraph by simply moving the tap stop icons on the ruler. To do this, position the mouse pointer anywhere on the paragraph, then,
- To create a first-line indent or hanging indent, drag to the position where you want the text to start.
- To change the left indent, drag to the position where you want the paragraph to start.
- To change the right indent, drag to the position where you want the paragraph to end.
Formatting the text in a text box
The text you enter into a text box can be formatted to suit your requirements. For example, you can change the font size, color, alignment, and highlight the text with a distinguishing color. To do this:
- Select the text you want to format, right-click and click Font on the shortcut menu.
- In the Font tab of the Format Text dialog, specify the font settings.
- When done, click OK to accept the changes.
You can also format the selected text by clicking the corresponding buttons on the Format toolbar, or commands of the Text Style submenu on the Format menu.
Finding or replacing a text string
To find a character string in a text box:
- Right-click anywhere in the text box and select Find a String from the shortcut menu.
- In the Find tab of the Find and Replace dialog, specify the string you want to search for and set the other settings as required.
- Click the Find Next button to start finding the specified string.
Similar to finding text, if you want to replace a string in the text box with another one,
- Right-click anywhere in the text box and select Replace from the shortcut menu, the Find and Replace dialog will then be displayed with the Replace tab selected.
- Specify the settings according to your requirements and click the Replace or Replace All button to replace the next or all the specified string with another one.
Importing and exporting text
To import text into a text box from an external file (.txt or .rtf):
- Position the mouse pointer at the location where you want to insert the imported text, then right-click and select Import External File.
- In the Import a File dialog, select the .txt or .rtf file you want to import and click OK.
The text of the file is inserted in the text box.
To export the text from a text box:
- Position the mouse pointer on the text, right-click and select Save to RTF File.
- In the Save RTF File dialog, specify the name of the file and click OK.
See an example: The SampleComponents catalog, included with JReport Designer, contains reports that have examples of how each component type could be used in a report. For the text box example, open <install_root>\Demo\Reports\SampleComponents\ForTextBox.cls
.