本文整理汇总了Java中javax.swing.JTextArea.getHighlighter方法的典型用法代码示例。如果您正苦于以下问题:Java JTextArea.getHighlighter方法的具体用法?Java JTextArea.getHighlighter怎么用?Java JTextArea.getHighlighter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextArea
的用法示例。
在下文中一共展示了JTextArea.getHighlighter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseExited
import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void mouseExited(MouseEvent e) {
JTextArea area = TEdit.getTextArea();
Highlighter hilite = area.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
if(hilites != null&&hilites.length>0)
TEdit.getSwingPool().put("area.hilites", hilites);
/*
if(hilites != null&&hilites.length>0){
TEdit.setEnabled("Delete", true);
TEdit.setEnabled("Calc",true);
}
else{
TEdit.setEnabled("Delete", false);
TEdit.setEnabled("Calc",false);
}
*/
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
示例2: 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);
}
}
示例3: mouseReleased
import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void mouseReleased(MouseEvent e) {
JTextArea area = TEdit.getTextArea();
Highlighter hilite = area.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
if(hilites != null&&hilites.length>0){
TEdit.setEnabled("Delete", true);
TEdit.setEnabled("Calc",true);
}
else{
TEdit.setEnabled("Delete", false);
TEdit.setEnabled("Calc",false);
}
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
示例4: keyReleased
import javax.swing.JTextArea; //导入方法依赖的package包/类
@Override
public void keyReleased(KeyEvent e) {
JTextArea area = TEdit.getTextArea();
Highlighter hilite = area.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
if(hilites != null&&hilites.length>0){
TEdit.setEnabled("Delete", true);
TEdit.setEnabled("Calc",true);
}
else{
TEdit.setEnabled("Delete", false);
TEdit.setEnabled("Calc",false);
}
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
示例5: 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);
}
}