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

x33g5p2x  于2022-02-01 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(66)

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

Utilities.getBreakLocation介绍

暂无

代码示例

代码示例来源:origin: net.sf.kerner-utils/kerner-utils

/**
 * Calculate the position on which to break (wrap) the line.
 * 
 * @param doc
 *            the document
 * @param p0
 *            start position
 * @param p1
 *            end position
 * @return the actual end position, will be <code>p1</code> if content does
 *         not need to wrap, otherwise it will be less than <code>p1</code>.
 */
protected int calculateBreakPosition(final Document doc, final int p0, final int p1) {
  final Segment segment = SegmentCache.getSegment();
  try {
    doc.getText(p0, p1 - p0, segment);
  } catch (final BadLocationException e) {
    throw new Error("Can't get line text");
  }
  final int width = paintTextR.width;
  final int p = p0 + Utilities.getBreakLocation(segment, metrics, 0, width, null, p0);
  SegmentCache.releaseSegment(segment);
  return p;
}

代码示例来源:origin: com.fifesoft.rtext/fife.common

public String getHTMLFileName(String fileName) {
  int br = 0;
  int count = 0;
  Font font = getFont();
  if (font==null) return ""; // Happens at the very beginning.
  FontMetrics fm = getFontMetrics(font);
  String result = "";
  do {
    // Subtract 8 from the width for a little "cushion" on
    // each side, and to prevent the HTML view from messing
    // us up view-wise.
    Segment s = new Segment(fileName.toCharArray(), 0,fileName.length());
    br = Utilities.getBreakLocation(s, fm, 0f, getWidth()-8,
                  null, 0);
    result += fileName.substring(0,br);
    fileName = fileName.substring(br);
    if (fileName.length()>0)
      result += "<br>";
    count++;
  } while (fileName.length()>0);
  // Make sure the icon is big enough to display all the text...
  setSize(DEFAULT_ICON_WIDTH, defaultHeight+(count-1)*fm.getHeight());
  return result;
}

相关文章