當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicGraphicsUtils.drawString方法代碼示例

本文整理匯總了Java中javax.swing.plaf.basic.BasicGraphicsUtils.drawString方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicGraphicsUtils.drawString方法的具體用法?Java BasicGraphicsUtils.drawString怎麽用?Java BasicGraphicsUtils.drawString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.plaf.basic.BasicGraphicsUtils的用法示例。


在下文中一共展示了BasicGraphicsUtils.drawString方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDrawEmptyString

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
private static void testDrawEmptyString() {
    JLabel label = new JLabel();
    BufferedImage buffImage = createBufferedImage(50, 50);
    Graphics2D g2 = buffImage.createGraphics();
    g2.setColor(DRAW_COLOR);
    BasicGraphicsUtils.drawString(null, g2, null, 0, 0);
    BasicGraphicsUtils.drawString(label, g2, null, 0, 0);
    BasicGraphicsUtils.drawString(null, g2, "", 0, 0);
    BasicGraphicsUtils.drawString(label, g2, "", 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, null, 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, null, 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, "", 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, "", 3, 0, 0);
    g2.dispose();
    checkImageIsEmpty(buffImage);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:bug8132119.java

示例2: checkNullArgumentsDrawString

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
private static void checkNullArgumentsDrawString(JComponent comp, Graphics2D g,
        String text) {

    float x = 50;
    float y = 50;
    BasicGraphicsUtils.drawString(null, g, text, x, y);
    BasicGraphicsUtils.drawString(comp, g, null, x, y);

    try {
        BasicGraphicsUtils.drawString(comp, null, text, x, y);
    } catch (NullPointerException e) {
        return;
    }

    throw new RuntimeException("NPE is not thrown");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:bug8132119.java

示例3: paintText

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
@Override
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();
    
    /* Draw the Text */
    if(model.isEnabled()) {
        /*** paint the text normally */
        g.setColor(b.getForeground());
        BasicGraphicsUtils.drawString(g,text, model.getMnemonic(),
                textRect.x,
                textRect.y + fm.getAscent());
    } else {
        /*** paint the text disabled ***/
   //     g.setColor(getDisabledTextColor());
        g.setColor(b.getForeground().brighter());
        BasicGraphicsUtils.drawString(g,text,model.getMnemonic(),
                textRect.x, textRect.y + fm.getAscent());
        
    }
}
 
開發者ID:sebkur,項目名稱:montemedia,代碼行數:23,代碼來源:CustomButtonUI.java

示例4: drawStringUnderlineCharAt

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
public static void drawStringUnderlineCharAt(JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) {
    Graphics2D g2D = (Graphics2D) g;
    Object savedRenderingHint = null;
    if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
        savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
        g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
    }
    if (getJavaVersion() >= 1.6) {
        try {
            Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2");
            Class classParams[] = {JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE};
            Method m = swingUtilities2Class.getMethod("drawStringUnderlineCharAt", classParams);
            Object methodParams[] = {c, g, text, underlinedIndex, x, y};
            m.invoke(null, methodParams);
        } catch (Exception ex) {
            BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
        }
    } else if (getJavaVersion() >= 1.4) {
        BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, underlinedIndex, x, y);
    } else {
        BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
    }
    if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
        g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
    }
}
 
開發者ID:Gocnak,項目名稱:Botnak,代碼行數:27,代碼來源:JTattooUtilities.java

示例5: testDrawString

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
private static void testDrawString(boolean underlined) {
    String str = "AOB";
    JComponent comp = createComponent(str);

    BufferedImage buffImage = createBufferedImage(WIDTH, HEIGHT);
    Graphics2D g2 = buffImage.createGraphics();

    g2.setColor(DRAW_COLOR);
    g2.setFont(comp.getFont());

    FontMetrics fontMetrices = comp.getFontMetrics(comp.getFont());
    float width = BasicGraphicsUtils.getStringWidth(comp, fontMetrices, str);
    float x = (WIDTH - width) / 2;
    int y = 3 * HEIGHT / 4;

    if (underlined) {
        BasicGraphicsUtils.drawStringUnderlineCharAt(comp, g2, str, 1, x, y);
    } else {
        BasicGraphicsUtils.drawString(comp, g2, str, x, y);
    }
    g2.dispose();

    float xx = BasicGraphicsUtils.getStringWidth(comp, fontMetrices, "A") +
            BasicGraphicsUtils.getStringWidth(comp, fontMetrices, "O")/2;

    checkImageContainsSymbol(buffImage, (int) xx, underlined ? 3 : 2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:bug8132119.java

示例6: drawString

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void drawString(Graphics g, String s, int accChar, int textX, int textY) {
  UISettings.setupAntialiasing(g);
  if (s.indexOf('\n') == -1)
    BasicGraphicsUtils.drawString(g, s, accChar, textX, textY);
  else {
    String[] strs = splitStringByLines(s);
    int height = g.getFontMetrics().getHeight();
    // Only the first line can have the accel char
    BasicGraphicsUtils.drawString(g, strs[0], accChar, textX, textY);
    for (int i = 1; i < strs.length; i++) {
      g.drawString(strs[i], textX, textY + (height * i));
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:15,代碼來源:MultiLineLabelUI.java

示例7: paintTab

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
public void paintTab(Graphics2D graphics, JTabbedPane tabPane, Rectangle tabBounds,
                     String tabText, Icon tabIcon, boolean isSelected,
                     boolean isMouseOverCloseButton, boolean isMousePressedOverCloseButton) {

    paintTabBackgroundAndBorder(graphics, tabBounds, isSelected);
    paintCloseButton(graphics, tabBounds, isSelected, isMouseOverCloseButton,
            isMousePressedOverCloseButton);

    FontMetrics fontMetrics = graphics.getFontMetrics();
    int closeButtonWidth = fCloseButtonIcon.getWidth();

    int textWidth = fontMetrics.stringWidth(tabText);

    int widthRequiredForCloseButton =
            fCloseButtonLocation.calculateWidthRequiredForCloseButton(closeButtonWidth);
    boolean tooWide = textWidth > tabBounds.width - widthRequiredForCloseButton - CONTENT_DISTANCE_FROM_EDGE;

    Rectangle adjustedTabRect = new Rectangle();
    adjustedTabRect.x = tooWide
            ? fCloseButtonLocation.calculateContentX(tabBounds, closeButtonWidth) : tabBounds.x;
    adjustedTabRect.y = tabBounds.y;
    adjustedTabRect.width = tooWide
            ? tabBounds.width - widthRequiredForCloseButton - CONTENT_DISTANCE_FROM_EDGE
            : tabBounds.width;
    adjustedTabRect.height = tabBounds.height;

    ICON_BOUNDS.x = 0;
    ICON_BOUNDS.y = 0;

    String clippedText = SwingUtilities.layoutCompoundLabel(tabPane, fontMetrics, tabText, tabIcon,
            SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.TRAILING,
            adjustedTabRect, ICON_BOUNDS, TEXT_BOUNDS, 4);

    int textX = fCloseButtonLocation.adjustXToPreventEncroachment(tabBounds, closeButtonWidth, TEXT_BOUNDS);
    int textY = TEXT_BOUNDS.y + fontMetrics.getAscent();
    graphics.setColor(tabPane.getForeground());
    BasicGraphicsUtils.drawString(graphics, clippedText, -1, textX, textY);
}
 
開發者ID:mathieulegoc,項目名稱:SmartTokens,代碼行數:39,代碼來源:EPTabPainter.java

示例8: drawString

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void drawString(Graphics g, String s, int accChar, int textX, int textY) {
  UIUtil.applyRenderingHints(g);
  if (s.indexOf('\n') == -1)
    BasicGraphicsUtils.drawString(g, s, accChar, textX, textY);
  else {
    String[] strs = splitStringByLines(s);
    int height = g.getFontMetrics().getHeight();
    // Only the first line can have the accel char
    BasicGraphicsUtils.drawString(g, strs[0], accChar, textX, textY);
    for (int i = 1; i < strs.length; i++) {
      g.drawString(strs[i], textX, textY + (height * i));
    }
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:15,代碼來源:MultiLineLabelUI.java

示例9: paintText

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void paintText(Graphics g)
{
    FontMetrics fm = g.getFontMetrics();
    String toPaint = this.applicationMenuButton.getText();

    // compute the insets
    int fullInsets = this.applicationMenuButton.getInsets().left;
    int pw = this.getPreferredSize(this.applicationMenuButton).width;
    int mw = this.getMinimumSize(this.applicationMenuButton).width;
    int w = this.applicationMenuButton.getWidth();
    int h = this.applicationMenuButton.getHeight();
    int insets = fullInsets - (pw - w) * (fullInsets - 2) / (pw - mw);

    // and the text rectangle
    Rectangle textRect = new Rectangle(insets,
            1 + (h - fm.getHeight()) / 2, w - 2 * insets, fm.getHeight());

    // show the first characters that fit into the available text rectangle
    while (true)
    {
        if (toPaint.length() == 0)
        {
            break;
        }
        int strWidth = fm.stringWidth(toPaint);
        if (strWidth <= textRect.width)
        {
            break;
        }
        toPaint = toPaint.substring(0, toPaint.length() - 1);
    }
    g.setColor(Color.white);
    BasicGraphicsUtils.drawString(g, toPaint, -1, textRect.x, textRect.y
            + fm.getAscent());
}
 
開發者ID:Alidron,項目名稱:designer,代碼行數:36,代碼來源:FileRibbonApplicationMenuButtonUI.java

示例10: drawString

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void drawString( Graphics g, String s, int accChar, int textX, int textY )
{
   	if( s.indexOf('\n') == -1 )
		BasicGraphicsUtils.drawString(g, s, accChar, textX, textY);
   	else
   	{
   		String[] strs = splitStringByLines( s );
   		int height = g.getFontMetrics().getHeight();
   		// Only the first line can have the accel char
   		BasicGraphicsUtils.drawString(g, strs[0], accChar, textX, textY);
   		for( int i = 1; i < strs.length; i++ )
   			g.drawString( strs[i], textX, textY + (height*i) );
   	}
}
 
開發者ID:NCIP,項目名稱:cagrid-general,代碼行數:15,代碼來源:MultiLineLabelUI.java

示例11: paintEnabledText

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY) {
  int accChar = l.getDisplayedMnemonic();
  g.setColor(l.getForeground());
  BasicGraphicsUtils.drawString(g, s, accChar, textX, textY);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:6,代碼來源:RightAlignedLabelUI.java

示例12: paintDisabledText

import javax.swing.plaf.basic.BasicGraphicsUtils; //導入方法依賴的package包/類
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) {
  int accChar = l.getDisplayedMnemonic();
  g.setColor(l.getBackground());
  BasicGraphicsUtils.drawString(g, s, accChar, textX, textY);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:6,代碼來源:RightAlignedLabelUI.java


注:本文中的javax.swing.plaf.basic.BasicGraphicsUtils.drawString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。