Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTextArea refresh problem 1

Status
Not open for further replies.

prosper

Programmer
Sep 4, 2001
631
HK
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.

Thanks for any help!
 
If you're referring to the half-lines of text that appear on the bottom of the text area, you can eliminate those by ending your last line with \n:

"aid of their party.\n";

"When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top