javax.swing.plaf.basic.BasicGraphicsUtils#drawString ( )源码实例Demo

下面列出了javax.swing.plaf.basic.BasicGraphicsUtils#drawString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: bug8132119.java
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);
}
 
源代码2 项目: openjdk-jdk9   文件: bug8132119.java
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");
}
 
源代码3 项目: openjdk-jdk9   文件: bug8132119.java
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);
}
 
源代码4 项目: consulo   文件: MultiLineLabelUI.java
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));
    }
  }
}
 
源代码5 项目: ghidra   文件: GraphicsUtils.java
public static void drawString(JComponent c, Graphics g, String text, int x, int y) {
	BasicGraphicsUtils.drawString(c, getGraphics2D(g), text, x, y);
}
 
源代码6 项目: ghidra   文件: GraphicsUtils.java
public static void drawString(JComponent c, Graphics2D g2d, String text, int x, int y) {
	BasicGraphicsUtils.drawString(c, g2d, text, x, y);
}
 
源代码7 项目: consulo   文件: RightAlignedLabelUI.java
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);
}
 
源代码8 项目: consulo   文件: RightAlignedLabelUI.java
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);
}