/**
* File name: jscrollpanedemo. Java
* Environment: GNU/Linux Ubuntu 7.04 + eclipse 3.2 + JDK 1.6
* Function: a simple example of scrolling display panel and scroll bar,
* Prepare the livaplayer lyrics display module.
* Version: 0.0.1.0
* Authors: 88250
* Date: 2007.5.4
* E-mail & MDN: DL88250@gmail.com
* QQ: 845765
*/
Import javax. Swing .*;
Import java. AWT .*;
Import java. AWT. event .*;
Public class jscrollpanedemo extends jframe
{
Private jpanel jtextpanel = new jpanel ();
Private jscrollpane jtextscrollpanel = new jscrollpane ();
Private borderlayout borderlayout1 = new borderlayout ();
Private jtextarea jtextarer = new jtextarea ();
Private jpanel jbuttonpanel = new jpanel ();
Private string STR = "start 1"
+ "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"
+ "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"
+ "End 1 ";
Private jbutton jendbutton = new jbutton ();
Private jbutton jstartbutton = new jbutton ();
Private jbutton jautoscrollbutton = new jbutton ();
Private int scrollpointy = 0;
Public jscrollpanedemo ()
{
Super ("scrollpanel Demo ");
This. setdefaclocloseoperation (jframe. exit_on_close );
Jtextpanel. setlayout (borderlayout1 );
Jtextarer. settext (this. Str );
Jtextscrollpanel
. Sethorizontalscrollbarpolicy (jscrollpane. horizontal_scrollbar_as_needed );
Jtextscrollpanel
. Setverticalscrollbarpolicy (jscrollpane. vertical_scrollbar_as_needed );
Jendbutton. settext ("end ");
Jendbutton. addactionlistener (New java. AWT. event. actionlistener ()
{
Public void actionreceivmed (actionevent E)
{
Jendbuttonactionreceivmed (E );
}
});
Jstartbutton. settext ("START ");
Jstartbutton. addactionlistener (New java. AWT. event. actionlistener ()
{
Public void actionreceivmed (actionevent E)
{
Jstartbuttonactionreceivmed (E );
}
});
Jautoscrollbutton. settext ("Auto ");
Jautoscrollbutton. addactionlistener (New java. AWT. event. actionlistener ()
{
Public void actionreceivmed (actionevent E)
{
Jautoscrollbuttonactionreceivmed (E );
}
});
This. getcontentpane (). Add (jtextpanel, borderlayout. center );
Jtextpanel. Add (jtextscrollpanel, borderlayout. center );
Jtextpanel. Add (jbuttonpanel, borderlayout. South );
Jbuttonpanel. Add (jendbutton, null );
Jbuttonpanel. Add (jstartbutton, null );
Jbuttonpanel. Add (jautoscrollbutton, null );
Jtextscrollpanel. getviewport (). Add (jtextarer, null );
Setbounds (600,400,300,300 );
Setvisible (true );
}
Private void jendbuttonactionreceivmed (actionevent E)
{
Int Height = 10;
Point P = new point ();
P. setlocation (0, this. jtextarer. getlinecount () * Height );
This. jtextscrollpanel. getviewport (). setviewposition (P );
Jtextarer. updateui ();
}
Private void jstartbuttonactionreceivmed (actionevent E)
{
Point P = new point (0, 0 );
This. jtextscrollpanel. getviewport (). setviewposition (P );
Jtextarer. updateui ();
}
Private void jautoscrollbuttonactionreceivmed (actionevent E)
{
For (INT I = 0; I <jtextarer. getfont (). getsize ()
* Jtextarer. getlinecount (); I ++)
{
Jtextscrollpanel. getverticalscrollbar (). setvalue (I );
Try
{
Thread. Sleep (30 );
}
Catch (interruptedexception IE)
{
Ie. printstacktrace ();
}
}
}
Public static void main (string [] ARGs)
{
Jscrollpanedemo scrollpanel = new jscrollpanedemo ();
}
}