This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes scrollpane not scrolling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "scrollpane not scrolling" Watch "scrollpane not scrolling" New topic
Author

scrollpane not scrolling

Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

my Jtext area does not scroll when overflowing, any ideas?



Jesus lives
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
You haven't put any scrolling components onto your app.
Have a look at JScrollPane in the API.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
give the preferredSize to the scrollpane, not the textArea

replace
jTextArea = new JTextArea();
Dimension d = new Dimension(100,100);
jTextArea.setPreferredSize(d);
contentPane.add(new JScrollPane(jTextArea),BorderLayout.SOUTH);

with this
jTextArea = new JTextArea();
JScrollPane sp = new JScrollPane(jTextArea);
Dimension d = new Dimension(100,100);
sp.setPreferredSize(d);
contentPane.add(sp,BorderLayout.SOUTH);
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

Thanks, thats great. I wonder why thats the only way it works.

I have another question. How do you write a new line to a JTextArea, similar to System.out.println.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
How do you write a new line to a JTextArea
Let's see if I can get it right this time; I was mistaken earlier.

What about the append method?
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

yes that works by using

but it seems rather clumsy.

How would you go about enabling a right mouse click over a JTextArea to bring a copy past menu. Is there code avail that does this

[ July 04, 2006: Message edited by: Nikos Katsikanis ]
[ July 04, 2006: Message edited by: Nikos Katsikanis ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> How would you go about enabling a right mouse click over a JTextArea to bring a copy past menu.
> Is there code avail that does this

Nothing standard, but not difficult to do with a JPopupMenu
 
wood burning stoves
 
subject: scrollpane not scrolling