javax.swing.text.JTextComponent#repaint ( )源码实例Demo

下面列出了javax.swing.text.JTextComponent#repaint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: CaretItem.java
/**
 * Set new caret bounds while repainting both original and new bounds.
 * Clear the caret-painted and update-caret-bounds flags.
 *
 * @param newCaretBounds non-null new bounds
 */
synchronized Rectangle setCaretBoundsWithRepaint(Rectangle newCaretBounds, JTextComponent c, String logMessage, int logIndex) {
    Rectangle oldCaretBounds = this.caretBounds;
    boolean repaintOld = (oldCaretBounds != null && (this.statusBits & CARET_PAINTED) != 0);
    this.statusBits &= ~(CARET_PAINTED | UPDATE_CARET_BOUNDS);
    boolean log = EditorCaret.LOG.isLoggable(Level.FINE);
    if (repaintOld) {
        if (log) {
            logRepaint(logMessage + "-setBoundsRepaint-repaintOld", logIndex, oldCaretBounds);
        }
        c.repaint(oldCaretBounds); // First schedule repaint of the original bounds (even if new bounds will possibly be the same)
    }
    if (!repaintOld || !newCaretBounds.equals(oldCaretBounds)) {
        if (log) {
            logRepaint(logMessage + "-setBoundsRepaint-repaintNew", logIndex, newCaretBounds);
        }
        c.repaint(newCaretBounds);
    }
    this.caretBounds = newCaretBounds;
    return oldCaretBounds;
}
 
源代码2 项目: java-swing-tips   文件: MainPanel.java
@Override public void updateUI() {
  super.updateUI();
  setOpaque(false);
  Caret caret = new DefaultCaret() {
    // [UnsynchronizedOverridesSynchronized]
    // Unsynchronized method damage overrides synchronized method in DefaultCaret
    @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
    @Override protected synchronized void damage(Rectangle r) {
      if (Objects.nonNull(r)) {
        JTextComponent c = getComponent();
        x = 0;
        y = r.y;
        width = c.getSize().width;
        height = r.height;
        c.repaint();
      }
    }
  };
  // caret.setBlinkRate(getCaret().getBlinkRate());
  caret.setBlinkRate(UIManager.getInt("TextArea.caretBlinkRate"));
  setCaret(caret);
}
 
源代码3 项目: java-swing-tips   文件: MainPanel.java
public static void setHighlight(JTextComponent jtc, String pattern, HighlightPainter painter) {
  Highlighter highlighter = jtc.getHighlighter();
  highlighter.removeAllHighlights();
  Document doc = jtc.getDocument();
  try {
    String text = doc.getText(0, doc.getLength());
    Matcher matcher = Pattern.compile(pattern).matcher(text);
    int pos = 0;
    while (matcher.find(pos) && !matcher.group().isEmpty()) {
      int start = matcher.start();
      int end = matcher.end();
      highlighter.addHighlight(start, end, painter);
      pos = end;
    }
  } catch (BadLocationException | PatternSyntaxException ex) {
    UIManager.getLookAndFeel().provideErrorFeedback(jtc);
  }
  jtc.repaint();
}
 
源代码4 项目: java-swing-tips   文件: MainPanel.java
@Override public void updateUI() {
  super.updateUI();
  Caret caret = new DefaultCaret() {
    // [UnsynchronizedOverridesSynchronized]
    // Unsynchronized method damage overrides synchronized method in DefaultCaret
    @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
    @Override protected synchronized void damage(Rectangle r) {
      if (Objects.nonNull(r)) {
        JTextComponent c = getComponent();
        x = 0;
        y = r.y;
        width = c.getSize().width;
        height = r.height;
        c.repaint();
      }
    }
  };
  // caret.setBlinkRate(getCaret().getBlinkRate());
  caret.setBlinkRate(UIManager.getInt("TextArea.caretBlinkRate"));
  setCaret(caret);
}
 
/** 
 * Fetches the previous caret location, stores the current caret location, 
 * If the caret is on another line, repaint the previous line and the current line 
 * 
 * @param c the text component 
 */ 
private static void currentLineChanged(JTextComponent c) {
    try { 
        int previousCaret = ((Integer) c.getClientProperty(PREVIOUS_CARET)).intValue(); 
        Rectangle prev = c.modelToView(previousCaret); 
        Rectangle r = c.modelToView(c.getCaretPosition()); 
        c.putClientProperty(PREVIOUS_CARET, new Integer(c.getCaretPosition())); 
 
        if ((prev != null) && (prev.y != r.y)) { 
            c.repaint(0, prev.y, c.getWidth(), r.height); 
            c.repaint(0, r.y, c.getWidth(), r.height); 
        } 
    } catch (BadLocationException e) {
    	// ignore
    } 
}
 
源代码6 项目: FlatLaf   文件: FlatTextFieldUI.java
static void propertyChange( JTextComponent c, PropertyChangeEvent e ) {
	switch( e.getPropertyName() ) {
		case FlatClientProperties.PLACEHOLDER_TEXT:
		case FlatClientProperties.COMPONENT_ROUND_RECT:
			c.repaint();
			break;

		case FlatClientProperties.MINIMUM_WIDTH:
			c.revalidate();
			break;
	}
}
 
源代码7 项目: pushfish-android   文件: Utility.java
/**
 * Scrolls the specified text component so the text between the starting and ending index are visible.
 */
public static void scrollToText(JTextComponent textComponent, int startingIndex, int endingIndex) {
    try {
        Rectangle startingRectangle = textComponent.modelToView(startingIndex);
        Rectangle endDingRectangle = textComponent.modelToView(endingIndex);

        Rectangle totalBounds = startingRectangle.union(endDingRectangle);

        textComponent.scrollRectToVisible(totalBounds);
        textComponent.repaint();
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码8 项目: pushfish-android   文件: Utility.java
/**
 * Scrolls the specified text component so the text between the starting and ending index are visible.
 */
public static void scrollToText(JTextComponent textComponent, int startingIndex, int endingIndex) {
    try {
        Rectangle startingRectangle = textComponent.modelToView(startingIndex);
        Rectangle endDingRectangle = textComponent.modelToView(endingIndex);

        Rectangle totalBounds = startingRectangle.union(endDingRectangle);

        textComponent.scrollRectToVisible(totalBounds);
        textComponent.repaint();
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码9 项目: netbeans   文件: BaseCaret.java
private void updateRectangularSelectionPaintRect() {
    // Repaint current rect
    JTextComponent c = component;
    Rectangle repaintRect = rsPaintRect;
    if (rsDotRect == null || rsMarkRect == null) {
        return;
    }
    Rectangle newRect = new Rectangle();
    if (rsDotRect.x < rsMarkRect.x) { // Swap selection to left
        newRect.x = rsDotRect.x; // -1 to make the visual selection non-empty
        newRect.width = rsMarkRect.x - newRect.x;
    } else { // Extend or shrink on right
        newRect.x = rsMarkRect.x;
        newRect.width = rsDotRect.x - newRect.x;
    }
    if (rsDotRect.y < rsMarkRect.y) {
        newRect.y = rsDotRect.y;
        newRect.height = (rsMarkRect.y + rsMarkRect.height) - newRect.y;
    } else {
        newRect.y = rsMarkRect.y;
        newRect.height = (rsDotRect.y + rsDotRect.height) - newRect.y;
    }
    if (newRect.width < 2) {
        newRect.width = 2;
    }
    rsPaintRect = newRect;

    // Repaint merged region with original rect
    if (repaintRect == null) {
        repaintRect = rsPaintRect;
    } else {
        repaintRect = repaintRect.union(rsPaintRect);
    }
    c.repaint(repaintRect);
    
    updateRectangularSelectionPositionBlocks();
}
 
源代码10 项目: netbeans   文件: CaretItem.java
synchronized Rectangle repaint(JTextComponent c, String logMessage, int logIndex) {
    Rectangle bounds = this.caretBounds;
    if (bounds != null) {
        this.statusBits &= ~CARET_PAINTED;
        if (EditorCaret.LOG.isLoggable(Level.FINE)) {
            logRepaint(logMessage, logIndex, bounds);
        }
        c.repaint(bounds);
    }
    return bounds;
}
 
源代码11 项目: netbeans   文件: CaretItem.java
/**
 * Repaint caret bounds if the caret is showing or do nothing
 * @param c
 * @return 
 */
synchronized Rectangle repaintIfShowing(JTextComponent c, String logMessage, int logIndex) {
    Rectangle bounds = this.caretBounds;
    if (bounds != null) {
        boolean repaint = (this.statusBits & CARET_PAINTED) != 0;
        if (repaint) {
            this.statusBits &= ~CARET_PAINTED;
            if (EditorCaret.LOG.isLoggable(Level.FINE)) {
                logRepaint(logMessage + "-repaintIfShowing", logIndex, bounds);
            }
            c.repaint(bounds);
        }
    }
    return bounds;
}
 
源代码12 项目: netbeans   文件: EditorCaret.java
private void updateRectangularSelectionPaintRect() {
    // Repaint current rect
    JTextComponent c = component;
    Rectangle repaintRect = rsPaintRect;
    if (rsDotRect == null || rsMarkRect == null) {
        return;
    }
    Rectangle newRect = new Rectangle();
    if (rsDotRect.x < rsMarkRect.x) { // Swap selection to left
        newRect.x = rsDotRect.x; // -1 to make the visual selection non-empty
        newRect.width = rsMarkRect.x - newRect.x;
    } else { // Extend or shrink on right
        newRect.x = rsMarkRect.x;
        newRect.width = rsDotRect.x - newRect.x;
    }
    if (rsDotRect.y < rsMarkRect.y) {
        newRect.y = rsDotRect.y;
        newRect.height = (rsMarkRect.y + rsMarkRect.height) - newRect.y;
    } else {
        newRect.y = rsMarkRect.y;
        newRect.height = (rsDotRect.y + rsDotRect.height) - newRect.y;
    }
    if (newRect.width < 2) {
        newRect.width = 2;
    }
    rsPaintRect = newRect;

    // Repaint merged region with original rect
    if (repaintRect == null) {
        repaintRect = rsPaintRect;
    } else {
        repaintRect = repaintRect.union(rsPaintRect);
    }
    c.repaint(repaintRect);
    
    updateRectangularSelectionPositionBlocks();
}
 
源代码13 项目: Pushjet-Android   文件: Utility.java
/**
 * Scrolls the specified text component so the text between the starting and ending index are visible.
 */
public static void scrollToText(JTextComponent textComponent, int startingIndex, int endingIndex) {
    try {
        Rectangle startingRectangle = textComponent.modelToView(startingIndex);
        Rectangle endDingRectangle = textComponent.modelToView(endingIndex);

        Rectangle totalBounds = startingRectangle.union(endDingRectangle);

        textComponent.scrollRectToVisible(totalBounds);
        textComponent.repaint();
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码14 项目: Pushjet-Android   文件: Utility.java
/**
 * Scrolls the specified text component so the text between the starting and ending index are visible.
 */
public static void scrollToText(JTextComponent textComponent, int startingIndex, int endingIndex) {
    try {
        Rectangle startingRectangle = textComponent.modelToView(startingIndex);
        Rectangle endDingRectangle = textComponent.modelToView(endingIndex);

        Rectangle totalBounds = startingRectangle.union(endDingRectangle);

        textComponent.scrollRectToVisible(totalBounds);
        textComponent.repaint();
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
源代码15 项目: java-swing-tips   文件: MainPanel.java
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
@Override protected synchronized void damage(Rectangle r) {
  if (Objects.nonNull(r)) {
    JTextComponent c = getComponent();
    x = r.x;
    y = r.y;
    // width = c.getFontMetrics(c.getFont()).charWidth('w');
    // width = c.getFontMetrics(c.getFont()).charWidth('\u3042');
    width = c.getFontMetrics(c.getFont()).charWidth('あ');
    height = r.height;
    c.repaint();
  }
}