本文整理匯總了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());
}