Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel + text

 
Robert Cross
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Robert Cross
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic