This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using setBounds or setLocation on JTextArea isn't working  RSS feed

 
Harry Weps
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am adding a JTextArea to my JPanel with this code:



Whenever I use setLocation(0,0), the JTextArea never moves. It is always in the top middle of the screen, not at (0,0). The same goes for setBounds(0,0,100,100) BUT the height and width are set this way, just not the location. Why is this?

Full Code

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!
The proper way to add a child to a parent is to set a proper layout manager to the parent and then add the child to it, using constraints if any.
e.g.


Your Canvas class extends JPanel. JPanel defaults to FlowLayout.
To fix your problem
1) Explicitly set the layout to BorderLayout
2) Wrap your JTextArea inside a JScrollPane
3) Add the scroll pane to the Canvas
Explicitly setting the layout/bounds is always a bad idea.

I will move this question over to a more appropriate forum for you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!