How to adjust font size on image resize? [duplicate]

妖精的绣舞 提交于 2019-12-12 06:59:06

问题


Possible Duplicate:
How to edit a text that is converted into image? or any other approach to realize/edit text

What I am trying to achieve is that... I have a text in textpane which I am converting to BufferedImage and resizing the size of the image by dragging it with mouse. Now If I want to edit the text, I am clicking on the image which hides the image and shows the text from textpane.

My problem is the size of the text in textpane is not resized(increased/decreased) as resize was done on image and not on text. So how do I change the font size as and when I resize the image containg text?


回答1:


You can adjust the font size by deriving the base font with a AffineTransform. Basically, you will need to maintain a reference to the base font that the user started with. When you need to, you would derive a new font instance by suppling a AffineTransform with the appropriate scale and apply that to the text pane

See Font#deriveFont(AffineTransform trans) for more details




回答2:


Try to scale the JTextPane's content as described here http://java-sl.com/Scale_In_JEditorPane.html

Just listen resize and adapt the scale factor acordingly



来源:https://stackoverflow.com/questions/13544015/how-to-adjust-font-size-on-image-resize

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!