/*
* 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();
}