This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!