问题
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