javax.swing.text.JTextComponent.modelToView()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中javax.swing.text.JTextComponent.modelToView()方法的一些代码示例,展示了JTextComponent.modelToView()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.modelToView()方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:modelToView

JTextComponent.modelToView介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Override
 public void run() {
  try {
   int endPos = component.getDocument().getLength();
   Rectangle rect = component.modelToView(endPos);
   if (rect != null && rect.y != lastHeight) {
    setPreferredWidth();
    repaint();
    lastHeight = rect.y;
   }
  } catch (BadLocationException ex) {
   /* nothing to do */
  }
 }
});

代码示例来源:origin: SonarSource/sonarqube

Rectangle r = component.modelToView(rowStartOffset);
int lineHeight = fontMetrics.getHeight();
int y = r.y + r.height;

代码示例来源:origin: stackoverflow.com

+ "Blabla\nBlabla\nBlabla\nBlabla\nBlabla";
int pos2 = textArea.getText().indexOf(turnToString2);
Rectangle startIndex = textArea.modelToView(pos2);
textArea.getHighlighter().addHighlight(pos2,
    pos2 + turnToString2.length(),

代码示例来源:origin: bobbylight/RSyntaxTextArea

private void adjustScrollIfNecessary(JTextComponent text,
              Rectangle visible, int initialY,
              int index) {
  try {
    Rectangle dotBounds = text.modelToView(index);
      if (dotBounds.y < visible.y ||
      (dotBounds.y > (visible.y + visible.height)) ||
      (dotBounds.y + dotBounds.height) >
      (visible.y + visible.height)) {
      int y;
      if (dotBounds.y < visible.y) {
        y = dotBounds.y;
      }
      else {
        y = dotBounds.y + dotBounds.height - visible.height;
      }
      if ((direction == -1 && y < initialY) ||
        (direction == 1 && y > initialY)) {
        // Only adjust if won't cause scrolling upward.
        visible.y = y;
      }
    }
  } catch (BadLocationException ble) {}
}

代码示例来源:origin: apache/pdfbox

private void scrollToWord(int offset)
{
  try
  {
    textComponent.scrollRectToVisible(textComponent.modelToView(offset));
  }
  catch (BadLocationException e)
  {
    e.printStackTrace();
  }
}

代码示例来源:origin: ron190/jsql-injection

char dotChar;
try {
  r = comp.modelToView(dot);
  if (r == null) {
    return;

代码示例来源:origin: org.gosu-lang.gosu/gosu-editor

private Rectangle getLocationFromOffset( int i ) throws BadLocationException
{
 Rectangle rectangle = _editor.modelToView( i );
 if( rectangle == null )
 {
  rectangle = TEST_RECTANGLE;
 }
 return rectangle;
}

代码示例来源:origin: abbot/abbot

@Override
  public Rectangle call() throws BadLocationException {
    Rectangle rect = tc.modelToView(index);
    return rect;
  }
};

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

private Rectangle getLocationFromOffset( int i ) throws BadLocationException
{
 Rectangle rectangle = _editor.modelToView( i );
 if( rectangle == null )
 {
  rectangle = TEST_RECTANGLE;
 }
 return rectangle;
}

代码示例来源:origin: hneemann/Digital

@Override
  public void run() {
    try {
      int endPos = component.getDocument().getLength();
      Rectangle rect = component.modelToView(endPos);
      if (rect != null && rect.y != lastHeight) {
        setPreferredWidth();
        repaint();
        lastHeight = rect.y;
      }
    } catch (BadLocationException ex) { /* nothing to do */ }
  }
});

代码示例来源:origin: hneemann/Digital

@Override
  public void run() {
    try {
      int endPos = component.getDocument().getLength();
      Rectangle rect = component.modelToView(endPos);
      if (rect != null && rect.y != lastHeight) {
        setPreferredWidth();
        repaint();
        lastHeight = rect.y;
      }
    } catch (BadLocationException ex) { /* nothing to do */ }
  }
});

代码示例来源:origin: apache/ctakes

@Override
  public void run() {
   try {
     int endPos = component.getDocument().getLength();
     Rectangle rect = component.modelToView( endPos );
     if ( rect != null && rect.y != lastHeight ) {
      setPreferredWidth();
      repaint();
      lastHeight = rect.y;
     }
   } catch ( BadLocationException ex ) { /* nothing to do */ }
  }
} );

代码示例来源:origin: org.sonarsource.sonarqube/sonar-scanner-protocol

@Override
 public void run() {
  try {
   int endPos = component.getDocument().getLength();
   Rectangle rect = component.modelToView(endPos);
   if (rect != null && rect.y != lastHeight) {
    setPreferredWidth();
    repaint();
    lastHeight = rect.y;
   }
  } catch (BadLocationException ex) {
   /* nothing to do */
  }
 }
});

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-bugtracking

private void scrollToCurrent() {
  try {
    Rectangle r1 = currentComp.modelToView(currentStart);
    Rectangle r2 = currentComp.modelToView(currentStart);
    Rectangle r = r1.union(r2);
    currentComp.scrollRectToVisible(r);
  } catch (BadLocationException blex) {
    BugtrackingManager.LOG.log(Level.INFO, blex.getMessage(), blex);
  }
}

代码示例来源:origin: robo-code/robocode

@Override
  public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {
    try {
      Rectangle r = c.modelToView(c.getCaretPosition());
      g.setColor(color);
      g.fillRect(0, r.y, c.getWidth(), r.height);
    } catch (BadLocationException ignore) {}
  }
};

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

private int getLineStart(int i) throws BadLocationException {
  Element line = editor.getDocument().getDefaultRootElement().getElement(i);
  Rectangle result = editor.modelToView(line.getStartOffset());
  if (result != null) {
    return result.y;
  }
  return -1;
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

private int getLineStart(int i) throws BadLocationException {
  Element line = editor.getDocument().getDefaultRootElement().getElement(i);
  Rectangle result = editor.modelToView(line.getStartOffset());
  
  if (result != null) {
    return result.y;
  }
  
  return -1;
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

private void drawError(SyntaxHighlightingScanner scanner, Graphics g, int x, int length, int y, boolean selected) throws BadLocationException {
  if (isErrorHighlighting()) {
    if (!selected) {
      g.setColor(new Color(255, 0, 0));
    }
    Rectangle rec = ((JTextComponent) getContainer()).modelToView(scanner.getStartOffset());
    
    if (rec != null) {
      drawZigZag(g, x, rec.x, length, y);
    }
  }
}

代码示例来源:origin: com.bitplan.antlr/com.bitplan.antlr

public void run() {
  try {
   int offset = component.getCaretPosition();
   Rectangle currentView = component.modelToView(offset);
   // Remove the highlighting from the previously highlighted line
   if (lastView.y != currentView.y) {
    component.repaint(0, lastView.y, component.getWidth(),
      lastView.height);
    lastView = currentView;
   }
  } catch (BadLocationException ble) {
  }
 }
});

代码示例来源:origin: org.gosu-lang.gosu/gosu-editor

public void displayContextMenu( IScriptEditor editor, int iXPos, int iYPos, Component eventSource )
 {
  editor.getEditor().requestFocus();
  try
  {
   Rectangle rcCaretBounds = editor.getEditor().modelToView( editor.getEditor().getCaretPosition() );
   getContextMenu( editor ).show( editor.getEditor(), rcCaretBounds.x, rcCaretBounds.y + rcCaretBounds.height );
  }
  catch( BadLocationException e )
  {
   throw new RuntimeException( e );
  }
 }
}

相关文章

JTextComponent类方法