File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

JPanel + text

Robert Cross
Greenhorn

Joined: Mar 28, 2004
Posts: 2
I'm having some problems printing text to a JPanel...do 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
http://java.sun.com/docs/books/tutorial/uiswing/components/text.html
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

...now 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, www.gsi3d.org.uk
Robert Cross
Greenhorn

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
Bartender

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
Sheriff

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: http://aspose.com/file-tools
 
subject: JPanel + text