我可以更胖 2021-04-15 17:23 采纳率: 0%
浏览 134

java的Graphics2D的drawString()方法写不出下滑线

Graphics2D graphics = image.createGraphics();
			// 设置笔刷白色
			graphics.setColor(Color.white);
			// 填充整个屏幕
			graphics.fillRect(0, 0, greWidth, greHeight);
			graphics.drawLine(0, 0, greWidth, greHeight);

			int preY = 0;
			for (QrcodeFont text : texts) {
				graphics.setColor(text.getColor());
				graphics.setFont(getFont(text.getFontSize()));
				text.setStartY(text.getStartY() == 0 ? preY + DEFAULT_FONT_SIZE + 1 : text.getStartY());
				graphics.drawString(new String(text.getText().getBytes(),"utf-8"), text.getStartX(), text.getStartY());
				preY = text.getStartY();
			}

这个方法文字能正常显示,但是_这种下滑线画不出来,怎么才能让下滑线显示出来

  • 写回答

3条回答 默认 最新

  • SoftwareTeacher 《编程之美》作者 2021-04-15 20:20
    关注

    这样如何? 

     JLabel label = new JLabel("Underlined Label");
    Font font = label.getFont();
    Map attributes = font.getAttributes();
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    label.setFont(font.deriveFont(attributes));
    评论

报告相同问题?