本文整理了Java中javax.swing.text.JTextComponent.getFontMetrics()
方法的一些代码示例,展示了JTextComponent.getFontMetrics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.getFontMetrics()
方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:getFontMetrics
暂无
代码示例来源:origin: groovy/groovy-core
protected synchronized void damage(Rectangle r) {
if (r != null) {
JTextComponent component = getComponent();
x = r.x;
y = r.y;
Font font = component.getFont();
width = component.getFontMetrics(font).charWidth('w');
height = r.height;
repaint();
}
}
}
代码示例来源:origin: SonarSource/sonarqube
fm = component.getFontMetrics(font);
fonts.put(key, fm);
代码示例来源:origin: SonarSource/sonarqube
FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
Insets insets = getInsets();
int availableWidth = getSize().width - insets.left - insets.right;
代码示例来源:origin: omegat-org/omegat
@Override
protected void paint(Graphics g, Rectangle rect, JTextComponent c) {
g.setColor(color);
FontMetrics fm = c.getFontMetrics(c.getFont());
int baseline = rect.y + rect.height - fm.getDescent() + 1;
g.drawLine(rect.x, baseline, rect.x + rect.width, baseline);
g.drawLine(rect.x, baseline + 1, rect.x + rect.width, baseline + 1);
}
}
代码示例来源:origin: omegat-org/omegat
@Override
protected void paint(Graphics g, Rectangle rect, JTextComponent c) {
g.setColor(color);
FontMetrics fm = c.getFontMetrics(c.getFont());
int baseline = rect.y + rect.height - fm.getDescent() + 1;
g.drawLine(rect.x, baseline, rect.x + rect.width, baseline);
}
}
代码示例来源:origin: omegat-org/omegat
protected void paint(Graphics g, Rectangle rect, JTextComponent c) {
Font f = c.getFont();
FontMetrics fm = c.getFontMetrics(f);
int y = rect.y - 1 + fm.getAscent();
g.setFont(f);
g.setColor(color);
g.drawString(symbol, rect.x, y);
}
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-editor
@Override
public Dimension getPreferredSize()
{
Dimension dim = new Dimension();
dim.height = _editor.getHeight();
FontMetrics fm = _editor.getFontMetrics( _editor.getFont() );
dim.width = fm.stringWidth( String.valueOf( dim.height / fm.getHeight() + 1 ) );
dim.width = Math.max( dim.width, GosuEditor.MIN_LINENUMBER_WIDTH );
dim.width += getLineInfoRequiredWidth();
return dim;
}
代码示例来源:origin: stackoverflow.com
public static int maxLinesVisibleInWindow(JTextComponent component)
{
Container container = getAncestorOfClass(JViewport.class, component);
if (container == null) return 0;
JViewport viewport = (JViewport)container;
int extentHeight = viewport.getExtentSize().height;
FontMetrics fm = component.getFontMetrics(component.getFont());
int characterHeight = fm.getHeight();
return (int)extentHeight/characterHeight - 1;
}
代码示例来源:origin: de.sciss/jsyntaxpane
/**
* Get the closest position within the document of the component that
* has given line and column.
* @param editor
* @param line the first being 1
* @param column the first being 1
* @return the closest positon for the text component at given line and
* column
*/
public static int getDocumentPosition(JTextComponent editor, int line,
int column) {
int lineHeight = editor.getFontMetrics(editor.getFont()).getHeight();
int charWidth = editor.getFontMetrics(editor.getFont()).charWidth('m');
int y = line * lineHeight;
int x = column * charWidth;
Point pt = new Point(x, y);
int pos = editor.viewToModel(pt);
return pos;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-designer
private static Dimension computeSizeForTextComponentColumns(JTextComponent textComponent, int columns) {
Dimension size = textComponent.getPreferredSize();
Font font = textComponent.getFont();
if (font == null) {
return size;
}
FontMetrics fontMetrics = textComponent.getFontMetrics(font);
if (fontMetrics == null) {
return size;
}
// Insets insets = textComponent.getInsets();
// int insetsWidth = insets == null ? 0 : insets.left + insets.right;
size.width = columns * (fontMetrics.charWidth('a'))/* + insetsWidth*/; // NOI18N
return size;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-navigation
void mouseClicked(JTextComponent c, Point p) {
Point position = new Point(p);
position.y += c.getFontMetrics(c.getFont()).getHeight();
SwingUtilities.convertPointToScreen(position, c);
performGoToAction(position);
}
代码示例来源:origin: org.codehaus.groovy/groovy-console
protected synchronized void damage(Rectangle r) {
if (r != null) {
JTextComponent component = getComponent();
x = r.x;
y = r.y;
Font font = component.getFont();
width = component.getFontMetrics(font).charWidth('w');
height = r.height;
repaint();
}
}
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
protected synchronized void damage(Rectangle r) {
if (r != null) {
JTextComponent component = getComponent();
x = r.x;
y = r.y;
Font font = component.getFont();
width = component.getFontMetrics(font).charWidth('w');
height = r.height;
repaint();
}
}
}
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
protected synchronized void damage(Rectangle r) {
if (r != null) {
JTextComponent component = getComponent();
x = r.x;
y = r.y;
Font font = component.getFont();
width = component.getFontMetrics(font).charWidth('w');
height = r.height;
repaint();
}
}
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
protected synchronized void damage(Rectangle r) {
if (r != null) {
JTextComponent component = getComponent();
x = r.x;
y = r.y;
Font font = component.getFont();
width = component.getFontMetrics(font).charWidth('w');
height = r.height;
repaint();
}
}
}
代码示例来源:origin: org.kohsuke.droovy/groovy
protected synchronized void damage(Rectangle r) {
if (r != null) {
JTextComponent component = getComponent();
x = r.x;
y = r.y;
Font font = component.getFont();
width = component.getFontMetrics(font).charWidth('w');
height = r.height;
repaint();
}
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-spi-quicksearch
protected int computePrefWidth () {
FontMetrics fm = command.getFontMetrics(command.getFont());
ProviderModel pModel = ProviderModel.getInstance();
int maxWidth = 0;
for (Category cat : pModel.getCategories()) {
// skip recent category
if (CommandEvaluator.RECENT.equals(cat.getName())) {
continue;
}
maxWidth = Math.max(maxWidth, fm.stringWidth(getHintText(cat)));
}
// don't allow width grow too much
return Math.min(350, maxWidth);
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-lab
@Override
public Dimension getPreferredSize()
{
Dimension dim = new Dimension();
dim.height = _editor.getHeight();
FontMetrics fm = _editor.getFontMetrics( _editor.getFont() );
int iLineHeight = fm.getHeight();
iLineHeight += getLineSpacingAttr( iLineHeight );
int iLines = getHeight() / iLineHeight;
dim.width = fm.stringWidth( String.valueOf( iLines ) );
dim.width = Math.max( dim.width, GosuEditor.MIN_LINENUMBER_WIDTH );
dim.width += getLineInfoRequiredWidth();
Insets borderInsets = getBorder().getBorderInsets( this );
dim.width += borderInsets.left + borderInsets.right;
return dim;
}
代码示例来源:origin: net.java.abeille/abeille
void checkLineLimit() {
BaseDocument doc = getDocument();
if (doc != null) {
Integer lineLimit = (Integer) doc.getProperty(BaseDocument.LINE_LIMIT_PROP);
if (lineLimit != null) {
if (component != null) {
// Not using FM cache - could be called too early
FontMetrics fm = component.getFontMetrics(getDefaultColoring().getFont());
if (fm != null) {
int charWidth = fm.stringWidth("A");
updateVirtualWidth(charWidth * lineLimit.intValue() + lineNumberWidth);
}
}
}
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
void checkLineLimit() {
BaseDocument doc = getDocument();
if (doc != null) {
Integer lineLimit = (Integer)doc.getProperty(BaseDocument.LINE_LIMIT_PROP);
if (lineLimit != null) {
if (component != null) {
// Not using FM cache - could be called too early
FontMetrics fm = component.getFontMetrics(getDefaultColoring().getFont());
if (fm != null) {
int charWidth = fm.stringWidth("A"); // NOI18N
updateVirtualWidth(charWidth * lineLimit.intValue() + lineNumberWidth);
}
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!