title: How to get width of a string in java
body: <p>I just started my comp science course and 3 weeks in I am already struggling. Using <code>BlueJ</code> I need to create a rectangle, with methods label, height of the rectangle, colour of the rectangle, position of both label and rectangle and width of rectangle. It basically has to look like a bar chart with text to the left of it therefore I need to figure out the width of the text in pixels so then i can subtract it from the <code>x</code> position of the rectangle. I have had no experience with java or programming to draw on a canvas before therefore I would need some sort of <code>label.getWidth();</code> command</p>