高分求助!关于Swing方面的问题 在JTextArea里面有setScrollOffset,或者通过setSelectionStart,setSelectionEnd来实现。我没做过(vc里面这种方法是没有问题的),你可以试一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这里有一个关于scoll的例子http://javaboutique.internet.com/Scrollup/ this.jTextArea1.requestFocus(); this.jTextArea1.setSelectionStart(this.jTextArea1.getText().length()); this.jTextArea1.setSelectionEnd(this.jTextArea1.getText().length()); 好象上边的方法不行是不是要将JTextArea1.SetEnable(True)有关还有是不是和ContentPane的Layout的设置有关我设置的XYLayout我的部分代码: contentPane.add(jScrollPane1, null); jScrollPane1.setAutoscrolls(true); jScrollPane1.getViewport().add(jTextArea2,null); jTextArea1.setLineWrap(true); this.jTextArea1.requestFocus(); this.jTextArea1.setSelectionStart(this.jTextArea1.getText().length());this.jTextArea1.setSelectionEnd(this.jTextArea1.getText().length()); 上面的方法是可行的,这是个例子,你看看import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Frame1 extends JFrame { private JPanel contentPane; private JLabel jLabel1 = new JLabel(); private JButton jb=new JButton("click"); private JPanel jp=new JPanel(new FlowLayout()); private JScrollPane jscr=new JScrollPane(); private JTextArea jta=new JTextArea(); public Frame1() { super("myFrame"); this.setSize(400,300); this.setResizable(false); this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add("South",jp); contentPane.add("Center",jscr); jscr.getViewport().add(jta); jta.setText("start\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend"); jp.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { click(e); } }); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); for(int i=1;i<=9;i++) { for(int j=1;j<=i;j++) { if(j!=1) System.out.print(","); System.out.print(j+"*"+i+"="+i*j); } System.out.println(""); } this.setVisible(true); } public void click(ActionEvent e) { this.jta.requestFocus(); this.jta.setSelectionStart(this.jta.getText().length()); this.jta.setSelectionEnd(this.jta.getText().length()); } public static void main(String args[]) { new Frame1(); }} 【菜鸟求助】没可用分了 大家帮忙看看那里错了 有谁做过棋牌的socket服务器?请进来讲讲经验~ 如何获取文件的时间 菜鸟基本问题总出现 最强大脑中的盲填数独,用程序有没有可能实现? 请教一个问题!望大家指点指点! 请看看这段代码有什么问题,为什么会陷入死锁呢? 小问题,送分 我是新手,遇到编译问题,请帮忙 help me!!!!我怎么将数据库中的数据用jTextfield 显示出呢??给一点代码把???? 如何读取一个超大文件? 给我一个词法分析器原代码,在线等候,给分520
http://javaboutique.internet.com/Scrollup/
this.jTextArea1.setSelectionStart(this.jTextArea1.getText().length());
this.jTextArea1.setSelectionEnd(this.jTextArea1.getText().length());
是不是要将JTextArea1.SetEnable(True)有关
还有是不是和ContentPane的Layout的设置有关我设置的XYLayout
我的部分代码:
contentPane.add(jScrollPane1, null);
jScrollPane1.setAutoscrolls(true);
jScrollPane1.getViewport().add(jTextArea2,null);
jTextArea1.setLineWrap(true);
this.jTextArea1.requestFocus();
this.jTextArea1.setSelectionStart(this.jTextArea1.getText().length());
this.jTextArea1.setSelectionEnd(this.jTextArea1.getText().length());
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class Frame1 extends JFrame {
private JPanel contentPane;
private JLabel jLabel1 = new JLabel();
private JButton jb=new JButton("click");
private JPanel jp=new JPanel(new FlowLayout());
private JScrollPane jscr=new JScrollPane();
private JTextArea jta=new JTextArea();
public Frame1() {
super("myFrame");
this.setSize(400,300);
this.setResizable(false);
this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add("South",jp);
contentPane.add("Center",jscr);
jscr.getViewport().add(jta);
jta.setText("start\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend");
jp.add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
click(e);
}
});
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
for(int i=1;i<=9;i++) {
for(int j=1;j<=i;j++) {
if(j!=1)
System.out.print(",");
System.out.print(j+"*"+i+"="+i*j);
}
System.out.println("");
}
this.setVisible(true);
} public void click(ActionEvent e) {
this.jta.requestFocus();
this.jta.setSelectionStart(this.jta.getText().length());
this.jta.setSelectionEnd(this.jta.getText().length());
} public static void main(String args[]) {
new Frame1();
}
}