Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: Following the last line
|
Posted: Mar 24, 2004 3:57 PM
|
|
Matthias,
Please do find the partial answer in this example ! There is still one thing I miss in my example ... Why is it well shown only after I resized it ? Not much else to say / write aboutit at the moment .... I am struggling with paint () & repaint
Cheers,
\T,
/* * Created on 24-Mar-04 * */ package com.tls.gui;
import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridBagLayout; import java.util.Random;
import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField;
/** * @author tsmets * */ public class ViewPort extends JFrame { public static final char[] LOWER_ALPHABET = "azertyuiopmlkjhgfdsqwxcvbn".toCharArray(); private JTextArea textArea = null; public ViewPort (String aFrameName) { super (aFrameName); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); setSize ( 400, 400); setVisible (true); textArea = new JTextArea ( "Test Scroll AREA "); JScrollPane scrollPane = new JScrollPane ( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.add (textArea); scrollPane.setViewportView (textArea); Container container = getContentPane(); JComponent component = new JPanel (); component.setOpaque (true); component.add (scrollPane); container.setLayout (new BorderLayout ()); container.add ( component, BorderLayout.CENTER); container.add ( new JTextField (40), BorderLayout.NORTH); new Thread (new TextAdder ()).start (); }
public static void main(String[] args) { new ViewPort ("TestFrame"); } public class TextAdder implements Runnable { Random random = new Random (); public void run () { int i = 0, j = 1; while (true) { if ( (i % j) == 0) { textArea.setText ( textArea.getText() + "\n"); j = Math.abs(random.nextInt()) % 80 + 1; System.out.println ("j = " + j); } System.out.println ("public void run () " + i); textArea.setText ( textArea.getText() + " " + LOWER_ALPHABET[++i % LOWER_ALPHABET.length] ); // This is what interests you textArea.setCaretPosition(textArea.getDocument().getLength()); try { Thread.sleep (5); } catch (Exception e) { System.out.println ("Exception. Message " + e.getMessage()); } } } } }
For colorizing of the code you just need to annoy Bill ;)
|
|