This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel and JTextArea problem  RSS feed

 
mark geroso
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I input text in the text area it starts in the center and extends beyond the window to the left. Why is that?


 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add these two lines at the end of the constructor



what prints out is the dimensions of the panel that contains the textArea.
now add some rows/columns to the textArea constructor, and run the program again

you should be able to work it out from the above
(also, a JTextArea generally should be in a JScrollPane)
 
mark geroso
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

you should be able to work it out from the above
(also, a JTextArea generally should be in a JScrollPane)


Thanks.

Ok, put JTextArea in JScrollPane.
Too used to html, thought it would automatically scroll.
 
R.Joe
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put your textarea in scrollpane and also mention the width and height of a textarea or set the layout of the panel as border which takes into center, panel have a default flowlayout
ex:
body = new JTextArea(20,30);
JScrollPane sp =new JScrollPane(body);
text.add(sp);

i hope it will help it out
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!