本文整理汇总了Java中javax.swing.JTextArea.replaceRange方法的典型用法代码示例。如果您正苦于以下问题:Java JTextArea.replaceRange方法的具体用法?Java JTextArea.replaceRange怎么用?Java JTextArea.replaceRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextArea
的用法示例。
在下文中一共展示了JTextArea.replaceRange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JTextArea area = TEdit.getTextArea();
Highlighter hilite = area.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
int Shift=0;
if(hilites != null){
if(hilites.length == 0 &&
TEdit.getSwingPool().containsKey("area.hilites")){
hilites = (Highlighter.Highlight[])TEdit.getSwingPool().get("area.hilites");
TEdit.getSwingPool().remove("area.hilites");
}
for (Highlighter.Highlight hilite1 : hilites) {
area.replaceRange("",hilite1.getStartOffset()-Shift, hilite1.getEndOffset()-Shift);
Shift = Shift -(hilite1.getEndOffset()-hilite1.getStartOffset());
}
if(hilites.length>0){
area.setCaretPosition(hilites[0].getStartOffset());
area.getCaret().setVisible(true);
}
TEdit.setEnabled("Calc",false);
TEdit.setEnabled("Delete",false);
TEdit.setEnabled("Save",true);
TEdit.setEnabled("SaveAs",true);
}
}
示例2: trunkTextArea
import javax.swing.JTextArea; //导入方法依赖的package包/类
public void trunkTextArea(JTextArea txtWin){
int numLinesToTrunk = txtWin.getLineCount() - SCROLL_BUFFER_SIZE;
if(numLinesToTrunk > 0)
{
try
{
int posOfLastLineToTrunk = txtWin.getLineEndOffset(numLinesToTrunk - 1);
txtWin.replaceRange("",0,posOfLastLineToTrunk);
}
catch (BadLocationException ex) {
ex.printStackTrace();
}
}
}
示例3: actionPerformed
import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JTextArea area = TEdit.getTextArea();
if(area.getText().length()==0){
JOptionPane.showMessageDialog(TEdit.getFrame(),"There is nothing to replace!");
return;
}
JTextField source = new JTextField();
JTextField target = new JTextField();
Object[] message = {
"Source:", source,
"Target:", target
};
int option = JOptionPane.showConfirmDialog(TEdit.getFrame(), message, "Replace", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE,myIcon);
if (option != JOptionPane.OK_OPTION)
return;
String src = source.getText();
String trgt= target.getText();
if(src.contentEquals(""))
return;
Highlighter hilite = area.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
int Shift=0;
String txt=area.getText();
if(hilites != null && hilites.length >0){
for (Highlighter.Highlight hilite1 : hilites) {
//txt.substring(hilite1.getStartOffset(), hilite1.getEndOffset()))
area.replaceRange(txt.substring(hilite1.getStartOffset(), hilite1.getEndOffset()).replace(src,trgt),
hilite1.getStartOffset()-Shift, hilite1.getEndOffset()-Shift);
Shift = Shift -(src.length()-trgt.length());
}
}
else{
txt=txt.replace(src,trgt);
area.setText(txt);
}
}