• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

JTextArea refresh problem  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!