i have a question regarding the vertical scrollpane in jdialog.when i run My application the jdialog vertical scrollbar displays end of the data.I need to scroll it upwards.How can i get the scrollbar bydefault at the top.
Asked
Active
Viewed 367 times
-1
-
are you meaning scroll to the left-top of JScrollPane – mKorbel Jun 30 '11 at 13:44
-
this is how my jdialog looks as soon as it runned. http://www.sendspace.com/file/tlk92l – hemanth kumar Jun 30 '11 at 13:58
-
Please don't post links to documents with proprietary formats; consider using a free image hosting website. – trashgod Jun 30 '11 at 15:43
2 Answers
2
What are you scrolling? If a text component, oftentimes setting the caret to the top of the component works. Please have a look at Rob Camick's Swing tips blog for more on this: Java Tips Weblog: Text Area Scrolling

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
textArea.setCaretPosition(textArea.getDocument().getLength());this works for displaying scrollbar bottom of the dialog.What should i use to display it to top of the dialog. – hemanth kumar Jun 30 '11 at 13:53
-
@hemanth: Try `textArea.setCaretPosition(0);` I have not tried this, but it seems the obvious solution. – Hovercraft Full Of Eels Jun 30 '11 at 13:57
-
Read the call, and read the documentation : setCaretPosition(int position). If you pass the length of the document, it goes to the end. What could you imagine to pass to make it go to the beginning? – JB Nizet Jun 30 '11 at 13:58
-
@hemanth: then you might wish to create a small compilable runnable program that demonstrates you problem, an [SSCCE](http://SSCCE.org), and post it in your question so we can test, alter and correct it. – Hovercraft Full Of Eels Jun 30 '11 at 14:00
-
got the result using this piece of code: jTextArea1.select(0,0); – hemanth kumar Jun 30 '11 at 14:22
-
Now i have a question. I have a url in jtextarea i need to change the color of it.How can i achieve this.Html tags are not working.. – hemanth kumar Jun 30 '11 at 14:23