开发者

drawing strings on jpanel

I want to draw string on jpanel but I do not know the number of string I am going to pass the panel开发者_如何学C in some cases there are four string in some cases there are five string in some cases there are three. Now how can I draw strings on panel and how many numbers of string will I have to pass to jPanel because they varies in each case.


What do you mean by the "number of string"? You mean it will be an array of Strings and you don't know the length ahead of time? Does each String need to go on a "line" by itself?

You could use the drawString method from the Graphics class.

Are you creating a class that extends JPanel. If so, then when you override paintComponent, the Graphics object is passed as a parameter.

This post contains information about how to determine the size of the String in pixels.

This link on measuring text and this link on displaying multiple lines of text may also be useful.

Cheers!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜