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

scrollpane not scrolling

 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my Jtext area does not scroll when overflowing, any ideas?

 
Campbell Ritchie
Sheriff
Posts: 48418
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't put any scrolling components onto your app.
Have a look at JScrollPane in the API.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48418
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic