Java Code Examples for javax.swing.plaf.basic.BasicGraphicsUtils#drawString()

The following examples show how to use javax.swing.plaf.basic.BasicGraphicsUtils#drawString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example 3
Source File: bug8132119.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: MultiLineLabelUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
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));
    }
  }
}
 
Example 5
Source File: GraphicsUtils.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public static void drawString(JComponent c, Graphics g, String text, int x, int y) {
	BasicGraphicsUtils.drawString(c, getGraphics2D(g), text, x, y);
}
 
Example 6
Source File: GraphicsUtils.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public static void drawString(JComponent c, Graphics2D g2d, String text, int x, int y) {
	BasicGraphicsUtils.drawString(c, g2d, text, x, y);
}
 
Example 7
Source File: RightAlignedLabelUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 8
Source File: RightAlignedLabelUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
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);
}