Simple Example of scrolling display panel and scroll bar

Source: Internet
Author: User
/**
* 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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.