javax.swing.JTextArea.getWidth()方法的使用及代码示例

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

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

JTextArea.getWidth介绍

暂无

代码示例

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

/**
 * Gets the preferred size of the overlay.
 * @param cols Description of the Parameter
 * @return The preferredSize value
 */
public Dimension getPreferredSize(int cols) {
  return new Dimension(textArea.getWidth(), textArea.getHeight());
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the right horizontal of the annotation
 * @param dx x offset
 */
public void adjustRight(int dx) {
  if (GUIConstants.ANNOTATION_MIN_WIDTH <= noteText.getWidth() + dx) {
    noteText.setSize(new Dimension(noteText.getWidth() + dx, noteText.getHeight()));
  }
}

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

public void actionPerformed(ActionEvent e) {
  BufferedImage img = new BufferedImage(text.getWidth(), text.getHeight(), BufferedImage.TYPE_INT_RGB);
  Graphics2D g2d = img.createGraphics();
  text.printAll(g2d);

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the left horizontal of the annotation
 * @param dx x offset
 */
public void adjustLeft(int dx) {
  if (GUIConstants.ANNOTATION_MIN_WIDTH <= noteText.getWidth() - dx) {
    noteText.setSize(new Dimension(noteText.getWidth() - dx, noteText.getHeight()));
    setLocation(getX() + dx, getY());
    originalX += dx;
  }
}

代码示例来源:origin: net.sf.squirrel-sql.plugins/firebirdmanager

/**
 * Refresh the textarea and scroll to the end
 */
private void refreshDisplay() {
  this.textArea.setCaretPosition(this.textArea.getDocument().getLength());
  this.textArea.scrollRectToVisible(this.textArea.getVisibleRect());
  this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
  this.textArea.paintImmediately(0,0,this.textArea.getWidth(), this.textArea.getHeight());
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the bottom vertical of the annotation
 * @param dy y offset
 */
public void adjustBottom(int dy) {
  if (noteText.getPreferredSize().height <= noteText.getHeight() + dy) {
    noteText.setSize(new Dimension(noteText.getWidth(), noteText.getHeight() + dy));
  }
}

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

public String formatText(JTextArea textArea)
{
  StringBuilder text = new StringBuilder( textArea.getText() );
  int lineHeight = textArea.getFontMetrics( textArea.getFont() ).getHeight();
  Point view = new Point(textArea.getWidth(), textArea.getInsets().top);
  int length = textArea.getDocument().getLength();
  int endOfLine = textArea.viewToModel(view);
  int lines = 0;

  while (endOfLine < length)
  {
    int adjustedEndOfLine = endOfLine + lines;

    if (text.charAt(adjustedEndOfLine) == ' ')
    {
      text.insert(adjustedEndOfLine + 1, '\n');
      lines++;
    }

    view.y += lineHeight;
    endOfLine = textArea.viewToModel(view);
  }

  return text.toString();
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Adjust the top vertical of the annotation
 * @param dy y offset
 */
public void adjustTop(int dy) {
  if (noteText.getPreferredSize().height <= noteText.getHeight() - dy) {
    noteText.setSize(new Dimension(noteText.getWidth(), noteText.getHeight() - dy));
    setLocation(getX(), getY() + dy);
    originalY += dy;
  }
}

代码示例来源:origin: org.simplericity.jettyconsole/jetty-console-core

text.setMaximumSize(new Dimension(text.getWidth(), 70));
scroll.setMaximumSize(new Dimension(text.getWidth(), 70));

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

@Override
public void componentResized(ComponentEvent e) {
  column.setWidth(textArea.getWidth());

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Calculates the BoundsOffsets used for setBounds() method
 *
 * Implemented because the canvas has no layout manager
 *
 */
public void updateBounds() {
  int newHeight = noteText.getPreferredSize().height;
  if (noteText.getHeight() < newHeight && newHeight >= noteText.getMinimumSize().height) {
    noteText.setSize(noteText.getWidth(), newHeight);
  }
  int rectWidth = noteText.getWidth() + GUIConstants.RESERVED_BORDER;
  int rectHeight = noteText.getHeight() + GUIConstants.RESERVED_BORDER;
  noteRect.setFrame(GUIConstants.RESERVED_BORDER / 2, GUIConstants.RESERVED_BORDER / 2, rectWidth, rectHeight);
  setSize(rectWidth + GUIConstants.ANNOTATION_SIZE_OFFSET, rectHeight + GUIConstants.ANNOTATION_SIZE_OFFSET);
  noteText.setLocation((int) noteRect.getX() + (rectWidth - noteText.getWidth()) / 2,
      (int) noteRect.getY() + (rectHeight - noteText.getHeight()) / 2);
  bounds.setBounds(model.getX() - 20, model.getY() - 20,
      rectWidth + GUIConstants.RESERVED_BORDER + GUIConstants.ANNOTATION_SIZE_OFFSET + 20,
      rectHeight + GUIConstants.RESERVED_BORDER + GUIConstants.ANNOTATION_SIZE_OFFSET + 20);
  setBounds(bounds);
}

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

private static int countLines(JTextArea textArea)
{
  AttributedString text = new AttributedString(textArea.getText());
  text.addAttribute(TextAttribute.FONT, textArea.getFont());
  FontRenderContext frc = textArea.getFontMetrics(textArea.getFont()).getFontRenderContext();
  AttributedCharacterIterator charIt = text.getIterator();
  LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(charIt, frc);
  Insets textAreaInsets = textArea.getInsets();
  float formatWidth = textArea.getWidth() - textAreaInsets.left - textAreaInsets.right;
  lineMeasurer.setPosition(charIt.getBeginIndex());

  int noLines = 0;
  while (lineMeasurer.getPosition() < charIt.getEndIndex())
  {
    lineMeasurer.nextLayout(formatWidth);
    noLines++;
  }

  return noLines;
}

相关文章

JTextArea类方法