本文整理匯總了Java中javax.swing.text.Highlighter.Highlight方法的典型用法代碼示例。如果您正苦於以下問題:Java Highlighter.Highlight方法的具體用法?Java Highlighter.Highlight怎麽用?Java Highlighter.Highlight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.Highlighter
的用法示例。
在下文中一共展示了Highlighter.Highlight方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mouseExited
import javax.swing.text.Highlighter; //導入方法依賴的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: useSelectedTextColor
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Determines whether the SelectedTextColor should be used for painting text
* foreground for the specified highlight.
*
* Returns true only if the highlight painter for the specified highlight
* is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
* or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
* is null or equals to the selection color of the text component.
*
* This is a hack for fixing both bugs 4761990 and 5003294
*/
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
Highlighter.HighlightPainter painter = h.getPainter();
String painterClass = painter.getClass().getName();
if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
return false;
}
try {
DefaultHighlighter.DefaultHighlightPainter defPainter =
(DefaultHighlighter.DefaultHighlightPainter) painter;
if (defPainter.getColor() != null &&
!defPainter.getColor().equals(c.getSelectionColor())) {
return false;
}
} catch (ClassCastException e) {
return false;
}
return true;
}
示例3: updateHighlighter
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void updateHighlighter() {
Highlighter.Highlight[] highlights = highlighter.getHighlights();
// remove old highlights
for (int i = 0; i < highlights.length; i++) {
highlighter.removeHighlight(highlights[i]);
}
String s = "";
try {
Document doc = inputField.getDocument();
s = doc.getText(0, doc.getLength());
} catch (BadLocationException e) {
}
if (s.length() == 0) {
return;
}
highlightErrorPosition();
int pos = inputField.getCaretPosition();
if (pos - 1 < 0) {
return;
}
if (pos - 1 >= s.length()) {
return;
}
highlightBrackets(s, pos);
highlightRNodes(s, pos);
}
示例4: actionPerformed
import javax.swing.text.Highlighter; //導入方法依賴的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);
}
}
示例5: mouseReleased
import javax.swing.text.Highlighter; //導入方法依賴的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.
}
示例6: keyReleased
import javax.swing.text.Highlighter; //導入方法依賴的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.
}
示例7: paint
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
@Override
public void paint(Graphics g) {
Highlighter.Highlight[] highlights = getHighlights();
for (int i = 0; i < highlights.length; i++) {
Highlighter.Highlight hl = highlights[i];
Rectangle bg = component.getBounds();
Insets insets = component.getInsets();
bg.x = insets.left;
bg.y = insets.top;
bg.height = insets.top + insets.bottom;
Highlighter.HighlightPainter painter = hl.getPainter();
painter.paint(g, hl.getStartOffset(), hl.getEndOffset(), bg, component);
}
}
示例8: removeHighlights
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/*****************************************
* removeHighlights
* remove all high lights from the pane
* @return void
*****************************************/
public void removeHighlights() {
JTextComponent textComp = this.textPane;
Highlighter hilite = textComp.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (int i=0; i<hilites.length; i++) {
if (hilites[i].getPainter() instanceof MyHighlightPainter){
hilite.removeHighlight(hilites[i]);
}
}
}
示例9: removeHighlights
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/*****************************************
* removeHighlights
* remove all high lights from the pane
*****************************************/
public void removeHighlights() {
JTextComponent textComp = this.textPane;
Highlighter hilite = textComp.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (Highlighter.Highlight hilite1 : hilites) {
if (hilite1.getPainter() instanceof MyHighlightPainter) {
hilite.removeHighlight(hilite1);
}
}
}
示例10: getHighlights
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Makes a copy of the highlights. Does not actually clone each highlight,
* but only makes references to them.
*
* @return the copy
* @see Highlighter#getHighlights
*/
public Highlighter.Highlight[] getHighlights() {
int size = highlights.size();
if (size == 0) {
return noHighlights;
}
Highlighter.Highlight[] h = new Highlighter.Highlight[size];
highlights.copyInto(h);
return h;
}
示例11: removeHighlights
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Removes only our private highlights
*/
@Action
public void removeHighlights() {
Highlighter hilite = jTextAreaEntry.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (Highlighter.Highlight hilite1 : hilites) {
if (hilite1.getPainter() instanceof MyHighlightPainter) {
hilite.removeHighlight(hilite1);
}
}
}
示例12: removeMarkers
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Removes only our private highlights This is public so that we can remove
* the highlights when the editorKit is unregistered. SimpleMarker can be
* null, in which case all instances of our Markers are removed.
*
* @param component the text component whose markers are to be removed
* @param marker the SimpleMarker to remove
*/
public static void removeMarkers(JTextComponent component, Highlighter.HighlightPainter marker) {
Highlighter hilite = component.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (int i = 0; i < hilites.length; i++) {
Highlighter.HighlightPainter hMarker = hilites[i].getPainter();
if (marker == null || hMarker.equals(marker)) {
hilite.removeHighlight(hilites[i]);
}
}
}
示例13: removeMarkers
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Removes only our private highlights
* This is public so that we can remove the highlights when the editorKit
* is unregistered. SimpleMarker can be null, in which case all instances of
* our Markers are removed.
* @param component the text component whose markers are to be removed
* @param marker the SimpleMarker to remove
*/
public static void removeMarkers(JTextComponent component, SimpleMarker marker) {
Highlighter hilite = component.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (int i = 0; i < hilites.length; i++) {
if (hilites[i].getPainter() instanceof SimpleMarker) {
SimpleMarker hMarker = (SimpleMarker) hilites[i].getPainter();
if (marker == null || hMarker.equals(marker)) {
hilite.removeHighlight(hilites[i]);
}
}
}
}
示例14: removeHighlights
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Remove all the Highlights from a JTextComponent
*
* @param component Instance of JTextComponent
*/
public void removeHighlights(JTextComponent component) {
Highlighter hilite = component.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (int i = 0; i < hilites.length; i++) {
if (hilites[i].getPainter() instanceof HighlightBookmark) {
hilite.removeHighlight(hilites[i]);
}
}
}
示例15: removeHighlights
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Remove all the Highlights from a JTextComponent
*
* @param component Instance of JTextComponent
*/
public void removeHighlights(JTextComponent component) {
Highlighter hilite = component.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (int i = 0; i < hilites.length; i++) {
if (hilites[i].getPainter() instanceof HighlightText) {
hilite.removeHighlight(hilites[i]);
}
}
}