• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JTextArea question .

 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
When text is appended in the JTextField. The new text is not visible and everytime the scrollbar has to be scrolled down to view the currecnt text . How can i avoid scrolling down when new text is entered . I have a chat window and every time a message is appended the scroll bar moves upwards and the currents message is not displayed .
Please Help .
Thanks in advance
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any inputs
Thanks in advance
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are probably other ways, but I think you can do:
(assuming your JTextArea is in a JScrollPane)

I don't remember if JTextPane.setCaretPosition() will automatically scroll the scrollpane, but you can try that as well.
Bill
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill
scroll = new JScrollPane(displaymessage);
scrollbar = scroll.getVerticalScrollBar();
scrollbar.setValue(scrollbar.getMaximum());
p1.add(scroll);
scroll is the Jscrollpane
scrollbar is the Jscrollbar
This is the code i've used but still the scollbars scroll upwards not downwards
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this -

You'll have to compute the rect accordingly.
Actually, this behaviour should be default.. maybe it's a bug or sth.
HTH,
- Manish
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
displaymessage.scrollRectToVisible(Rectangle rect);

From where the does the rectangle class come into picture ?
Manish if you could plz also have a look at the link below
[ May 12, 2003: Message edited by: raghav mathur ]
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by raghav mathur:
displaymessage.scrollRectToVisible(Rectangle rect);

From where the does the rectangle class come into picture ?


That would be the last rect (bottommost) that you'd want to make visible. Try this code

This will scroll your JTextArea a little, you'll have to find the height of your font and total number of lines in the JTextArea to get co-ordinates of the rect right. Trust me, this will work! Maybe, you'd want to use it with SwingUtilities.invokeLater().
Hmmm, let me have a look at the other link...
HTH,
- Manish
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to let you know - clueless about the jar and database driver problem.
- Manish
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Here is the code. This one did work on machine with J2SE 1.4 on Win2K.

Let me know if it works.
HTH,
- Manish
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manish Hatwalne:

Trust me, this will work!


It worked . Thanks a ton . One more thing :
see also :
https://coderanch.com/t/335743/GUI/java/setting-focus-component
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic