package com.drbob42.jbjar.tip31; import java.awt.*; import java.awt.event.*; import com.sun.java.swing.*; import borland.jbcl.control.*; import borland.jbcl.view.*; import borland.jbcl.model.*; /** * Sample application showing the use of the WrappedTextItemPainter * class. * * @author Hubert A. Klein Ikkink, aka Mr.Haki * @version 1.0 */ public class SampleFrame extends Frame { BorderLayout borderLayout1 = new BorderLayout(); FieldControl fieldControl1 = new FieldControl(); public SampleFrame() { try { jbInit(); /* * Assign WrappedTextItemPainter object to fieldControl1, * so the text will be wrapped if necessary */ fieldControl1.setViewManager(new BasicViewManager( new WrappedTextItemPainter())); /* * Assing long text to fieldControl1 */ fieldControl1.setText(createSampleText()); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { fieldControl1.setFlat(true); this.setLayout(borderLayout1); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { this_windowClosing(e); } }); this.add(fieldControl1, BorderLayout.CENTER); } /** * Create a String with a lot of text and new line characters * * @return Lenghty String */ private String createSampleText() { StringBuffer buf = new StringBuffer(); buf.append("Sample text\n\n"); buf.append("This text is to show you the use of the "); buf.append("WrappedTextItemPainter and a FieldControl component.\n"); buf.append("The WrappedTextItemPainter is capable of wrapping text "); buf.append("over multiple lines if the text is longer than one line.\n"); buf.append("And the WrappedTextItemPainter is capable of recognizing "); buf.append("the new line character (\'\\n\') and start on a new line.\n\n"); buf.append("Pretty neat, isn't it?"); return buf.toString(); } public static void main(String args[]) { SampleFrame f = new SampleFrame(); f.pack(); f.setVisible(true); } void this_windowClosing(WindowEvent e) { System.exit(0); } }