import javax.swing.*; import java.awt.*; public class TextScroll{ JTextArea2 jta; JScrollPane jsp; public TextScroll(){ jta = new JTextArea2(5, 20); jsp = new JScrollPane(jta); } public JScrollPane getJsp(){ return jsp; } public JTextArea2 getJta(){ return jta; } public static void main(String[] args) throws Exception{ Rectangle rec; int h, c; boolean nob; JFrame frame = new JFrame("Scrollint Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TextScroll st = new TextScroll(); JScrollPane js = st.getJsp(); frame.getContentPane().add(js); frame.setBounds(0, 0, 200, 135); frame.setVisible(true); JTextArea2 t = st.getJta(); t.setFont(new Font("Monospaced", Font.BOLD, 14)); h = t.getLineHeight(); c = 0; nob = true; while (++c < 11){ rec = t.getVisibleRect(); rec.y += h; t.scrollRectToVisible(rec); if (nob){ t.append("Love to live: " + c + "\n"); } else{ t.append("Live to love: " + c + "\n"); } Thread.sleep(1500); nob = (! nob); } t.setBackground(Color.yellow); } } class JTextArea2 extends JTextArea{ public JTextArea2(int col, int row){ super(col, row); } public int getLineHeight(){ return getRowHeight(); } }