我怎么将插入在TextArea中的内容显示在当前页面?详细内容请入内查看!! 应该是这样:set会使得TextArea显示到最新内容的底部。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用的是JDK1.3.1,没出现你所说的问题,或者说我没看清楚你的意思import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;class ScrollTest extends JFrame implements ActionListener{ private JTextArea txt = new JTextArea(); private JScrollPane scroll = new JScrollPane(txt); private JButton insertButton = new JButton("Insert"); private JButton appendButton = new JButton("Append"); private JTextField posText = new JTextField(5); private JTextField strText = new JTextField(10); public ScrollTest() { JPanel p = new JPanel(); p.add(new JLabel("Insert Position:")); p.add(posText); p.add(new JLabel("Insert String:")); p.add(strText); p.add(insertButton); p.add(appendButton); getContentPane().add(p, BorderLayout.NORTH); getContentPane().add(scroll, BorderLayout.CENTER); insertButton.addActionListener(this); appendButton.addActionListener(this); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(600, 400); setTitle("Scroll Test"); setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource()==insertButton) txt.insert(strText.getText()+"\n", Integer.parseInt(posText.getText())); else txt.append(strText.getText()+"\n"); //txt.getScrollableUnitIncrement(txt.getVisibleRect(), // SwingConstants.VERTICAL, 1); //scroll.scrollRectToVisible(txt.getVisibleRect()); } public static void main(String args[]) { new ScrollTest(); }} insert, append都很正常呀? 万万不可!!!swing对线程是不安全的必须用EventQueue.invokeLater看看http://www.csdn.net/expert/topic/1026/1026698.xml?temp=.122677 重写equals方法 关于substring和indexOf截取字符串 java.net.URL getResource(String name) 关于多态的问题 格式化字符串 同一个系统如何使用2个版本的jdk RCP 菜单问题 请问这是java的什么写法?就像以前第一次遇到内部类时的样子! FileWriter与BufferedWriter 通过互联网来访问我的电脑 急!!!运行一个包含小程序的网页IE总是出错。是不是IE的BUG?? 把java源程序生成应用程序有哪些方法?
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;class ScrollTest extends JFrame implements ActionListener
{
private JTextArea txt = new JTextArea();
private JScrollPane scroll = new JScrollPane(txt);
private JButton insertButton = new JButton("Insert");
private JButton appendButton = new JButton("Append");
private JTextField posText = new JTextField(5);
private JTextField strText = new JTextField(10);
public ScrollTest() {
JPanel p = new JPanel();
p.add(new JLabel("Insert Position:"));
p.add(posText);
p.add(new JLabel("Insert String:"));
p.add(strText);
p.add(insertButton);
p.add(appendButton);
getContentPane().add(p, BorderLayout.NORTH);
getContentPane().add(scroll, BorderLayout.CENTER);
insertButton.addActionListener(this);
appendButton.addActionListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(600, 400);
setTitle("Scroll Test");
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==insertButton)
txt.insert(strText.getText()+"\n", Integer.parseInt(posText.getText()));
else
txt.append(strText.getText()+"\n");
//txt.getScrollableUnitIncrement(txt.getVisibleRect(),
// SwingConstants.VERTICAL, 1);
//scroll.scrollRectToVisible(txt.getVisibleRect());
} public static void main(String args[]) { new ScrollTest();
}
}
swing对线程是不安全的
必须用EventQueue.invokeLater
看看
http://www.csdn.net/expert/topic/1026/1026698.xml?temp=.122677