当前位置: 首页>>代码示例>>Java>>正文


Java FontMetrics.getMaxDescent方法代码示例

本文整理汇总了Java中java.awt.FontMetrics.getMaxDescent方法的典型用法代码示例。如果您正苦于以下问题:Java FontMetrics.getMaxDescent方法的具体用法?Java FontMetrics.getMaxDescent怎么用?Java FontMetrics.getMaxDescent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.FontMetrics的用法示例。


在下文中一共展示了FontMetrics.getMaxDescent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMinimumSize

import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public Dimension getMinimumSize() {
    Dimension minSize = new Dimension();

    if (superIsButton) {
        minSize = super.getMinimumSize();
    } else {

        Graphics g = getGraphics();
        FontMetrics metrics = g.getFontMetrics();

        minSize.width = metrics.stringWidth(labelString) + 14;
        minSize.height = metrics.getMaxAscent()
                + metrics.getMaxDescent() + 9;

        g.dispose();
        g = null;
    }
    return minSize;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:LightweightEventTest.java

示例2: getFontDimensions

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * Figure out my font dimensions.
 */
private void getFontDimensions() {
    Graphics gr = getGraphics();
    FontMetrics fm = gr.getFontMetrics();
    maxDescent = fm.getMaxDescent();
    Rectangle2D bounds = fm.getMaxCharBounds(gr);
    int leading = fm.getLeading();
    textWidth = (int)Math.round(bounds.getWidth());
    // textHeight = (int)Math.round(bounds.getHeight()) - maxDescent;

    // This produces the same number, but works better for ugly
    // monospace.
    textHeight = fm.getMaxAscent() + maxDescent - leading;

    if (gotTerminus == true) {
        textHeight++;
    }

    if (getFontAdjustments() == false) {
        // We were unable to programmatically determine textAdjustX
        // and textAdjustY, so try some guesses based on VM vendor.
        String runtime = System.getProperty("java.runtime.name");
        if ((runtime != null) && (runtime.contains("Java(TM)"))) {
            textAdjustY = -1;
            textAdjustX = 0;
        }
    }
}
 
开发者ID:klamonte,项目名称:jermit,代码行数:31,代码来源:SwingScreen.java

示例3: createChip

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * Create a "chip" with the given text and colors.
 *
 * @param g Graphics2D for getting the FontMetrics.
 * @param text The text to display.
 * @param border The border {@code Color}.
 * @param background The background {@code Color}.
 * @param amount How much to fill the chip with the fill color
 * @param fill The fill {@code Color}.
 * @param foreground The foreground {@code Color}.
 * @param filled Whether the chip is filled or not
 * @return A chip.
 */
private BufferedImage createChip(Graphics2D g, String text,
                                 Color border, Color background,
                                 double amount, Color fill,
                                 Color foreground,
                                 Boolean filled) {
    Font font = FontLibrary.createFont(FontLibrary.FontType.SIMPLE,
        FontLibrary.FontSize.TINY, Font.BOLD, scaleFactor);
    FontMetrics fm = g.getFontMetrics(font);
    int padding = (int)(6 * scaleFactor);
    BufferedImage bi = new BufferedImage(fm.stringWidth(text) + padding,
        fm.getMaxAscent() + fm.getMaxDescent() + padding,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bi.createGraphics();
    g2.setFont(font);
    int width = bi.getWidth();
    int height = bi.getHeight();
    g2.setColor(border);
    g2.fillRect(0, 0, width, height);
    g2.setColor(background);
    g2.fillRect(1, 1, width - 2, height - 2);
    if (filled.equals(false)) {
        if (amount > 0.0 && amount <= 1.0) {
            g2.setColor(fill);
            g2.fillRect(1, 1, width - 2, (int)((height - 2) * amount));
        }
    }
    g2.setColor(foreground);
    g2.drawString(text, padding/2, fm.getMaxAscent() + padding/2);
    g2.dispose();
    return bi;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:45,代码来源:ImageLibrary.java

示例4: paint

import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {

    super.paint(g);
    Rectangle bounds = getBounds();
    if (superIsButton) {
        return;
    }
    Dimension size = getSize();
    Color oldColor = g.getColor();

    // draw border
    g.setColor(getBackground());
    g.fill3DRect(0, 0, size.width, size.height, false);
    g.fill3DRect(3, 3, size.width - 6, size.height - 6, true);

    // draw text
    FontMetrics metrics = g.getFontMetrics();
    int centerX = size.width / 2;
    int centerY = size.height / 2;
    int textX = centerX - (metrics.stringWidth(labelString) / 2);
    int textY = centerY
            + ((metrics.getMaxAscent() + metrics.getMaxDescent()) / 2);
    g.setColor(getForeground());
    g.drawString(labelString, textX, textY);

    g.setColor(oldColor);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:LightweightEventTest.java

示例5: calcPreferredSize

import java.awt.FontMetrics; //导入方法依赖的package包/类
private Dimension calcPreferredSize(HtmlRendererImpl r) {
    Insets ins = r.getInsets();
    Dimension prefSize = new java.awt.Dimension(ins.left + ins.right, ins.top + ins.bottom);
    String text = r.getText();

    Graphics g = r.getGraphics();
    Icon icon = r.getIcon();

    if (text != null) {
        FontMetrics fm = g.getFontMetrics(r.getFont());
        prefSize.height += (fm.getMaxAscent() + fm.getMaxDescent());
    }

    if (icon != null) {
        if (r.isCentered()) {
            prefSize.height += (icon.getIconHeight() + r.getIconTextGap());
            prefSize.width += icon.getIconWidth();
        } else {
            prefSize.height = Math.max(icon.getIconHeight() + ins.top + ins.bottom, prefSize.height);
            prefSize.width += (icon.getIconWidth() + r.getIconTextGap());
        }
    }
    
    //Antialiasing affects the text metrics, so use it if needed when
    //calculating preferred size or the result here will be narrower
    //than the space actually needed
    ((Graphics2D) g).addRenderingHints(getHints());

    int textwidth = textWidth(text, g, r.getFont(), r.isHtml()) + 4;

    if (r.isCentered()) {
        prefSize.width = Math.max(prefSize.width, textwidth + ins.right + ins.left);
    } else {
        prefSize.width += (textwidth + r.getIndent());
    }

    if (FIXED_HEIGHT > 0) {
        prefSize.height = FIXED_HEIGHT;
    }

    return prefSize;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:HtmlLabelUI.java

示例6: calcFontMetrics

import java.awt.FontMetrics; //导入方法依赖的package包/类
private void calcFontMetrics( Graphics2D g2d, int w, int h ) {
    FontMetrics fm;
    Graphics2D g2 = (Graphics2D)g2d.create();

    /// ABP
    if ( g2Transform != NONE && textToUse != FILE_TEXT ) {
        g2.setFont( g2.getFont().deriveFont( getAffineTransform( g2Transform )) );
        fm = g2.getFontMetrics();
    }
    else {
        fm = g2.getFontMetrics();
    }

    maxAscent = fm.getMaxAscent();
    maxDescent = fm.getMaxDescent();
    if (maxAscent == 0) maxAscent = 10;
    if (maxDescent == 0) maxDescent = 5;
    if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
        /// Give slight extra room for each character
        maxAscent += 3;
        maxDescent += 3;
        gridWidth = fm.getMaxAdvance() + 6;
        gridHeight = maxAscent + maxDescent;
        if ( force16Cols )
          numCharAcross = 16;
        else
          numCharAcross = ( w - 10 ) / gridWidth;
        numCharDown = ( h - 10 ) / gridHeight;

        canvasInset_X = ( w - numCharAcross * gridWidth ) / 2;
        canvasInset_Y = ( h - numCharDown * gridHeight ) / 2;
        if ( numCharDown == 0 || numCharAcross == 0 )
          throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );

        if ( !isPrinting )
          resetScrollbar( verticalBar.getValue() * numCharAcross );
    }
    else {
        maxDescent += fm.getLeading();
        canvasInset_X = 5;
        canvasInset_Y = 5;
        /// gridWidth and numCharAcross will not be used in this mode...
        gridHeight = maxAscent + maxDescent;
        numCharDown = ( h - canvasInset_Y * 2 ) / gridHeight;

        if ( numCharDown == 0 )
          throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
        /// If this is text loaded from file, prepares the LineBreak'ed
        /// text layout at this point
        if ( textToUse == FILE_TEXT ) {
            if ( !isPrinting )
              f2dt.fireChangeStatus( "LineBreaking Text... Please Wait", false );
            lineBreakTLs = new Vector();
            for ( int i = 0; i < fileText.length; i++ ) {
                AttributedString as =
                  new AttributedString( fileText[i], g2.getFont().getAttributes() );

                LineBreakMeasurer lbm =
                  new LineBreakMeasurer( as.getIterator(), g2.getFontRenderContext() );

                while ( lbm.getPosition() < fileText[i].length() )
                  lineBreakTLs.add( lbm.nextLayout( (float) w ));

            }
        }
        if ( !isPrinting )
          resetScrollbar( verticalBar.getValue() );
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:70,代码来源:FontPanel.java

示例7: lineToY

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * Converts a line index to a y co-ordinate.
 * 
 * @param line
 *            The line
 */
public int lineToY(int line) {
	FontMetrics fm = painter.getFontMetrics();
	return (line - firstLine) * fm.getHeight() - (fm.getLeading() + fm.getMaxDescent());
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:11,代码来源:JEditTextArea.java


注:本文中的java.awt.FontMetrics.getMaxDescent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。