19 February 2004 - java_dev (original) (raw)

Java developers

February 19th, 2004

06:17 pm - timwi - Text width/height How do I find out the size of rendered text?Specifically, I want to draw text in the middle of a JPanel. Something like this: public void paint (Graphics g) { int x = getWidth()/2 - getTextWidth ("String")/2; int y = getHeight()/2 - getTextHeight ("String")/2; g.drawString ("String", x, y); } Except, of course, that getTextWidth and getTextHeight don't exist, so what do I need to use?
11:37 pm - timwi - GridBagLayout problems Hi. I'm trying to lay out a series of components (panels, in this case, but that probably shouldn't matter) in a horizontal row.I'm currently using GridBagLayout for this. Let me know if I should be using something else.How do I tell GridBagLayout (or whatever other Layout Manager) to leave space between the components rather than sticking them right onto each other?Specifically, I want it to space them out evenly across the width of the parent container. So if there are, say, 10 of them, each with width 50, and the container has width 590, then there should be 10 pixels of space between them. If the parent container had width 500, they should be stuck onto each other.Thanks in advance...