关于TextArea的问题 pos是第几个..不是座标..大哥..比如第3个后面就是insert("",3) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 哦,谢谢但是如果我要插入在第2行第3列那里,现在前面有很多字符,空格之类的东西,难道要计算出这些的长度吗?我想比如这样做:insert("",180*2+3),为什么不可以啊,这时光标乱跑,并没有到那里 /* * TestLabel.java * * Created on 2003年8月24日, 下午9:46 */import javax.swing.*;import java.awt.*;import java.awt.event.*;public class TestLabel extends JFrame{ JTextArea area; /** Creates a new instance of TestLabel */ public TestLabel() { setDefaultCloseOperation(EXIT_ON_CLOSE); test2(); } private void test2() { area = new JTextArea(); getContentPane().add(area, "Center"); JButton btn = new JButton("goto"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { gotoPosition(2, 3); } }); getContentPane().add(btn, "North"); } private void gotoPosition(int line, int col) { try { int pos = area.getLineEndOffset(line-1); area.requestFocus(); area.setCaretPosition(pos+col-1); } catch(Exception e) { e.printStackTrace(); } } /** * @param args the command line arguments */ public static void main(String[] args) { JFrame f = new TestLabel(); f.setSize(100, 100); f.show(); } } Java 版本混乱 要用到别人开发的(不包含在JDK中的).jar包,应该怎么设置呢? 编写网络五子棋的问题 请问Servlet如何用WINDOWS的画图板打开图片?? 急救,十万火急! java i/o中有这样的函数吗? 如何在FilenameFilter 的 accpet(File dir,String name)里面判断是否是一个目录? ant的最奇怪的问题,求教各位!!! 如何使用jdk 蔡鸟散分——我刚装上jbuilder,请问怎样用它进行编译程序呢? 在jdk哪里找那些系统的类? Java初学的问题
但是如果我要插入在第2行第3列那里,现在前面有很多字符,空格之类的东西,难道要计算出这些的长度吗?我想比如这样做:insert("",180*2+3),为什么不可以啊,这时光标乱跑,并没有到那里
* TestLabel.java
*
* Created on 2003年8月24日, 下午9:46
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class TestLabel extends JFrame{
JTextArea area;
/** Creates a new instance of TestLabel */
public TestLabel() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
test2();
}
private void test2()
{
area = new JTextArea();
getContentPane().add(area, "Center");
JButton btn = new JButton("goto");
btn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
gotoPosition(2, 3);
}
});
getContentPane().add(btn, "North");
} private void gotoPosition(int line, int col)
{
try
{
int pos = area.getLineEndOffset(line-1);
area.requestFocus();
area.setCaretPosition(pos+col-1);
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame f = new TestLabel();
f.setSize(100, 100);
f.show();
}
}