Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JTextArea refresh problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try my code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextArea1b extends JApplet {
JTextArea jTA;
JPanel jp1,jp2;
JScrollPane jSPan;
JButton but1;
Point vp;
JViewport viewport;
public void init()
{
Container c = getContentPane();
jp1 = new JPanel();
jp2 = new JPanel();
String s = "Now is the\n" +
"time for all good men\n" +
"to come to the\n" +
"aid of their party.";
jTA = new JTextArea(s, 4, 20);
but1 = new JButton("scroll downwards");
c.setBounds(new Rectangle(0,0,400,400));
JScrollPane jSPan = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
viewport = jSPan.getViewport();
viewport.add(jTA);
c.setLayout(new FlowLayout());
c.add(jp1);
c.add(jp2);
jp1.setBackground(Color.BLACK);
jp2.setBackground(Color.RED);
jp2.setLayout(new BorderLayout());
jp2.add(jSPan,BorderLayout.CENTER);
jp2.add(but1,BorderLayout.SOUTH);
but1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
vp = viewport.getViewPosition();
vp.y+=10;
viewport.setViewPosition(vp);
}
});
}
}
The Jtextarea does not refresh well after I have clicked the button.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that the JTextArea isn't large enough to continue scrolling down... add some newlines to the end of the text...
reply
    Bookmark Topic Watch Topic
  • New Topic