简体   繁体   English

Java Swing g.drawString换行

[英]Java Swing g.drawString Word Wrap

I am working on a small little panel popup that displays a few values. 我正在处理一个显示一些值的小面板弹出窗口。 Basically when the player lands on a chance spot the game draws a card that does a few actions. 基本上,当玩家降落在偶然的机会上时,游戏会抓一张纸牌进行一些动作。 On the physical card panel I have a paint method with a drawString which draws the description of the card. 在物理卡面板上,我有一个带有drawString的paint方法,该方法绘制卡的描述。 Because the card is small in width, the description tends to draw off the edge of the card. 由于卡的宽度较小,因此说明倾向于画出卡的边缘。 Is there any way to make a word wrap so the description doesn't run off the edge of the card? 有什么办法可以自动换行,以使描述不会超出卡片的边缘吗?

See LabelRenderTest.java . 参见LabelRenderTest.java It uses a JLabel , which can not only render multi-line text, but also formatted text. 它使用JLabel ,它不仅可以呈现多行文本,还可以呈现带格式的文本。 In this example we render it to a BufferedImage , that is then drawn to the UI. 在此示例中,我们将其渲染到BufferedImage ,然后将其绘制到UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM