Meaningless Drivel is fun!
The moose likes Swing / AWT / SWT and the fly likes Caption with awt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Caption with awt" Watch "Caption with awt" New topic

Caption with awt

Soum Sark
Ranch Hand

Joined: May 31, 2002
Posts: 50
Hi how do i create a caption with Panels or Frames.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
what do you mean? could you be more specific?
Soum Sark
Ranch Hand

Joined: May 31, 2002
Posts: 50
Kind of like this.
----- Question 1 of 8 ------------------------
| ______________________________________ |
| | | |
| | This is a TextAre | |
| |_____________________________________| |

the outer border with rectangle kind of and with a caption 'Question # of #' . All the dotted lines will be continuous though (can't do it here in text. Hope you get it this time
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Oh, you mean like TitledBorder... unfortunately, components having borders was introduced in Swing, so you'll have to do this yourself by overriding the paint( Graphics ) method of Panel and paint the border on the component yourself. To figure out how big the caption should be you'll have to use the FontMetrics class to get the dimensions of the String... you'll also have to mess with setInsets() and getInsets() to make sure and put enough space around the component to draw the border correctly...
[ August 02, 2002: Message edited by: Nathan Pruett ]

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Caption with awt
It's not a secret anymore!