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