Hello Folks, I have written an application that manages the x and y position of a String object through two seperate JSlider objects. The Display Area for the String object is a subclass of the JPanel class. The content of the String object is updated through a JButton and JTextField objects. I was successful in writing the code up until where i could get the String from TextField and move it around using the Horizontal and vertical sliders. My problem here is as i move the sliders to it maximum value the string disappears out of the drawing area which according to my program should not disappear from the drawing area. Are there any methods that would keep the String from not disappearing the drawing area. Below is my code: It is very lengthy. My code compiles fine and executes too except for the above problem.
Thank you, kt [ July 24, 2005: Message edited by: kanaka tam ]
posted 10 years ago
You can determine the width an height of a string using the FontMetrics class.
An instance of FontMetrics can be acquired using the getFontMetrics method on component. You should pass the font that you are using to paint on you component (getFont). Then you can use the getStringBounds method to calculate the width and height of a string.
I do not know if this helps you out but it answers the question in your message header.