It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes JPanel + text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel + text" Watch "JPanel + text" New topic

JPanel + text

Robert Cross

Joined: Mar 28, 2004
Posts: 2
I'm having some problems printing text to a I need to override the paint method somehow? How would I do this?
I need to display a text file, basically, within a JPanel specifically (damn CS HW).
If you have some advice, that'd be great...I know you all get tons of HW problems...sorry to add another!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
You probably want to display it in a text area, or similar
This link might help
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
If you really want to write on the JPanel itself though you can override it's painting method, which is called paintComponent add an instance of MyTestPanel to your GUI layout, sending it the text you want displayed as the constructor argument, and you should get a JPanel with the text printed on it.

SCJP 1.4,
Robert Cross

Joined: Mar 28, 2004
Posts: 2
Thanks for the advice, I'll get to testing it out...
I'm printing an array of information, basically, to the JPanel.
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

Dys Fnctnl,
Welcome to Java Ranch, and we hope that you enjoy your stay. However, your display name does not comply with our Naming Policy. Please Change your Display Name to comply. (we are looking for names that are not obviously fictitious).

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
After you've changed your display name, let's continue this conversation over in the Swing / JFC / AWT forum, where they love to get all messy with this GUI stuff...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: JPanel + text
It's not a secret anymore!