本文整理汇总了Java中javax.swing.JTextArea.getCaretPosition方法的典型用法代码示例。如果您正苦于以下问题:Java JTextArea.getCaretPosition方法的具体用法?Java JTextArea.getCaretPosition怎么用?Java JTextArea.getCaretPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextArea
的用法示例。
在下文中一共展示了JTextArea.getCaretPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JTextArea area = TEdit.getTextArea();
String txt = area.getText();
if(txt == null)
return;
String s = TEdit.getLookingFor();
if(s.contentEquals(""))
return;
if(txt.contentEquals("") || txt.length()<1)
return;
if(area.getCaretPosition() >=txt.length()-1){
area.setCaretPosition(0);
//JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
//return;
}
int foundAt = txt.indexOf(s,area.getCaretPosition()+s.length());
if(foundAt == -1){
JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
return;
}
area.setCaretPosition(foundAt);
area.select(foundAt,foundAt+s.length());
}
示例2: makeCaretVisible
import javax.swing.JTextArea; //导入方法依赖的package包/类
private void makeCaretVisible (JTextArea textArea) {
int pos = textArea.getCaretPosition();
try {
Rectangle rec = textArea.getUI().modelToView(textArea, pos);
if (rec != null) {
Point p = SwingUtilities.convertPoint(textArea, rec.x, rec.y, this);
scrollRectToVisible(new Rectangle(p.x, p.y, rec.width, rec.height));
}
} catch (BadLocationException blex) {
LOG.log(Level.INFO, blex.getMessage(), blex);
}
}
示例3: makeCaretVisible
import javax.swing.JTextArea; //导入方法依赖的package包/类
void makeCaretVisible(JTextArea textArea) {
int pos = textArea.getCaretPosition();
try {
Rectangle rec = textArea.getUI().modelToView(textArea, pos);
if (rec != null) {
Point p = SwingUtilities.convertPoint(textArea, rec.x, rec.y, this);
scrollRectToVisible(new Rectangle(p.x, p.y, rec.width, rec.height));
}
} catch (BadLocationException blex) {
Bugzilla.LOG.log(Level.INFO, blex.getMessage(), blex);
}
}
示例4: actionPerformed
import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JTextArea area = TEdit.getTextArea();
String txt = area.getText();
if(txt == null)
return;
String s = TEdit.getLookingFor();
if(s.contentEquals(""))
return;
if(txt.contentEquals("") || txt.length()<1)
return;
if(area.getCaretPosition() < s.length()-1){
JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the beginning of the text");
return;
}
if(area.getCaretPosition()-s.length()<=0){
area.setCaretPosition(txt.length()-1);
}
int foundAt = txt.substring(0,area.getCaretPosition()-s.length()).lastIndexOf(s);
if(foundAt == -1){
JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the beginning of the text");
return;
}
area.setCaretPosition(foundAt);
area.select(foundAt,foundAt+s.length());
}