|Delphi Clinic||C++Builder Gate||Training & Consultancy||Delphi Notes Weblog||Dr.Bob's Webshop|
Show multiple lines of text wrapped
Designing a graphical user interface for our applications is quit easy in JBuilder 2. But sometimes we want something more than is offered by the IDE. For example JBuilder 2 doesn't have a control for showing multiple lines of text, that will wrap automatically to a new line when necessary. JBuilder 2 doesn't have a control that will interpret a new line character ('\n').
Well, maybe not right off the Component Palette, but it is easy to make one of the controls behave with the characteristics described above. A lot of the JBCL controls can be assigned objects called ItemPainters. These ItemPainters objects are able to show the data in a control the way we want it to be displayed. The ItemPainter classes can be found in the borland.jbcl.view package.
One of the ItemPainter classes is the WrappedTextItemPainter class. This class can show text and when it is necessary will wrap the text over multiple lines. This class also is capable of interpreting the new line character, so we have full control if want text to start on a new line.
Now we need a control to which we can attach the WrappedTextItemPainter class.
The FieldControl is a good choice, because this class support ItemPainter classes.
To assign our ItemPainter to a FieldControl object we must use the following code:
fieldControl1.setViewManager(new BasicViewManager(new WrappedTextItemPainter()));
And that is all to make our FieldControl object capable of wrapping text.
The following screenshots show the behavior or the text when a frame is resized:
Source code of the sample frame.