简单, 看看 tutorial doc 就能解决, 就看你看不看了.
ta JTextArea
tfRow JTextField
tfColumn JTextField
try
{
Document doc = ta.getDocument();
Element root = doc.getDefaultRootElement();
int row = Integer.parseInt(tfRow.getText());
int column = Integer.parseInt(tfColumn.getText());
if (row >= root.getElementCount())
{
row = root.getElementCount() - 1;
}
Element paragraph = root.getElement(row);
int offset = paragraph.getStartOffset();
if (paragraph.getEndOffset() - offset >= column)
{
offset += column;
}
ta.setCaretPosition(offset);
ta.requestFocus();
}
catch (Exception ex)
{
ex.printStackTrace();
}
ta JTextArea
tfRow JTextField
tfColumn JTextField
try
{
Document doc = ta.getDocument();
Element root = doc.getDefaultRootElement();
int row = Integer.parseInt(tfRow.getText());
int column = Integer.parseInt(tfColumn.getText());
if (row >= root.getElementCount())
{
row = root.getElementCount() - 1;
}
Element paragraph = root.getElement(row);
int offset = paragraph.getStartOffset();
if (paragraph.getEndOffset() - offset >= column)
{
offset += column;
}
ta.setCaretPosition(offset);
ta.requestFocus();
}
catch (Exception ex)
{
ex.printStackTrace();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货