The Artima Developer Community
Sponsored Link

Java Answers Forum
Vertical Scrollbar not scrolling down automatically

3 replies on 1 page. Most recent reply: Sep 18, 2003 9:09 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

Vertical Scrollbar not scrolling down automatically Posted: Sep 12, 2003 10:24 AM
Reply to this message Reply
Advertisement
I have a JTextpane with Vertical scrollbar(JScrollbar) and i am using Document for formatting text and icons inside the JTextPane. I am inserting strings into the document using Document.insertString(Document.length(), "dfd", mystyle).
The problem is that the whenever i am inserting Strings, i have to manually scroll down the VerticalScrollbar to see the last string inserted.The Vertical scrollbar is not automatically scrolling down to see the lasst string inserted.
i want it to be scroll automattically down so that i can see the last inserted strings.
What can i do on this pls help


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Vertical Scrollbar not scrolling down automatically Posted: Sep 13, 2003 2:47 AM
Reply to this message Reply
use
setAutoscrolls(boolean autoscrolls)

or scrollRectToVisible(Rectangle aRect)

sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

Re: Vertical Scrollbar not scrolling down automatically Posted: Sep 18, 2003 1:37 AM
Reply to this message Reply
Sorry i am using JScrollPane
Still it is not Scrolling Down

/*******************************************/
JTextPane textArea = new JTextPane()
{
public void paintComponent(Graphics g)
{
Dimension d=getSize();
g.drawImage(textAreaicon.getImage(), 0, 0,d.width,d.height,null);
setOpaque(false);
super.paintComponent(g);
}
};
textArea.setEditable(false);
areaScrollPane = new JScrollPane(textArea);
areaScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
areaScrollPane.setPreferredSize(new Dimension(500,370));
areaScrollPane.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(""),
BorderFactory.createEmptyBorder(5,5,5,5)),
areaScrollPane.getBorder()));
areaScrollPane.setBackground(TxtBorderColor);
areaScrollPane.setAutoscrolls(true);

Mdoc = textArea.getDocument();

def = StyleContext.getDefaultStyleContext().
getStyle(StyleContext.DEFAULT_STYLE);
Style BarS =textArea.addStyle("Bar",def);
StyleConstants.setAlignment(BarS, StyleConstants.ALIGN_CENTER);
StyleConstants.setIcon(BarS,new ImageIcon("BAR.gif"));


I am usning "Mdoc" as Document and inserting text in the text area using

Mdoc.insertString(Mdoc.getLength(),"Mystring",textArea.getStyle("mystyle "));

The Scroll bar is not scrolling down. pls help

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Vertical Scrollbar not scrolling down automatically Posted: Sep 18, 2003 9:09 AM
Reply to this message Reply
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.text.*;
public class LoadImage extends JFrame implements Runnable
{
	JScrollPane scrollPane,areaScrollPane;
	Thread thread;
	StyledDocument Mdoc;
	ImageIcon icon,textAreaicon;
	JTextPane textArea;
	String myString = "12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222"
					  +"12222222222222222222222222222222222222222222222222222222222222222222222222222";
					  
	public LoadImage()
	{
	}
	public static void main(String [] args)
	{
		LoadImage frame = new LoadImage();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.imageInEditPane();
		frame.setSize(300, 300);
		frame.setVisible(true);
	}
		
		
   public void imageInEditPane()
   {
   	textAreaicon = new ImageIcon("C:\\Documents and Settings\\amrashid\\My Documents\\My Pictures\\aminur.jpg");
   
   	textArea = new JTextPane()
	{
		public void paintComponent(Graphics g)
		{
			Dimension d=getSize();
			g.drawImage(textAreaicon.getImage(), 0, 0,d.width,d.height,null);
			setOpaque(false);
			super.paintComponent(g);
		}
	};
	textArea.setEditable(false);
	areaScrollPane = new JScrollPane();
	areaScrollPane.setViewportView(textArea);
	areaScrollPane.setVerticalScrollBarPolicy(
	JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
	areaScrollPane.setPreferredSize(new Dimension(500,370));
	areaScrollPane.setBorder(
	BorderFactory.createCompoundBorder(
	BorderFactory.createCompoundBorder(
	BorderFactory.createTitledBorder(""),
	BorderFactory.createEmptyBorder(5,5,5,5)),
	areaScrollPane.getBorder()));
	areaScrollPane.setBackground(Color.red);
	areaScrollPane.setAutoscrolls(true);
 
	Mdoc = (StyledDocument)textArea.getDocument();
	
 
	Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
	Style BarS =Mdoc.addStyle("Bar",def);
	StyleConstants.setAlignment(BarS, StyleConstants.ALIGN_CENTER);
	StyleConstants.setIcon(BarS,new ImageIcon("D:\\amin\\pic\\aminur.gif"));
	
	try
	{
		Mdoc.insertString(Mdoc.getLength(),myString,textArea.getStyle("mystyle "));
	} 
	catch (Exception e)
	{
		e.printStackTrace();
	}
	setContentPane( areaScrollPane );
	
	thread=new Thread(this);
    thread.setDaemon(true);
	thread.start();
   }
	public void run()
	   {
	       while(true)
	       {
	           SwingUtilities.invokeLater(new Runnable()
	           {
	               public void run()
	               {
						areaScrollPane.getVerticalScrollBar().setValue(areaScrollPane.getVerticalScrollBar().getMaximum());                   }
	           });
 
	            try
	           {
	                   Thread.currentThread().sleep(1000);
	           }
	           catch(Exception e){}
	       }
	       
	   }
 
}

Flat View: This topic has 3 replies on 1 page
Topic: glibc dependencies Previous Topic   Next Topic Topic: multi array

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use