package com.mindprod.example;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import java.awt.Container;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
/**
* demonstrate the use of javax.swing.JScrollPane.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2011-09-20 initial version
* @since 2011-09-20
*/
public final class TestJScrollPane
{
/**
* is user busy with the scroller?
*/
private static boolean userBusyScrolling;
/**
* Debugging harness for a Frame
*
* @param args command line arguments are ignored.
*/
public static void main( String args[] )
{
SwingUtilities.invokeLater( new Runnable()
{
/**
* fire up a JFrame on the Swing thread
*/
public void run()
{
final JFrame jFrame = new JFrame();
final Container contentPane = jFrame.getContentPane();
final JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setContentType( "text/html" );
jEditorPane.setEditable( false );
jEditorPane.setText( "<html lang=\"en-CA\"><body>The destructive Seven Blunders of the World that cause " +
"violence:\n" +
"<ol><li>Wealth without work.</li>\n" +
"<li>Pleasure without conscience.</li>\n" +
"<li>Knowledge without character.</li>\n" +
"<li>Commerce without morality.</li>\n" +
"<li>Science without humanity.</li>\n" +
"<li>Religion without sacrifice.</li>\n" +
"<li>Politics without principle.</li></ol>\n" +
"~ Mahatma Gandhi</body></html>\n" );
final JScrollPane scroller = new JScrollPane( jEditorPane,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
scroller.getVerticalScrollBar().setUnitIncrement( 16 );
scroller.getVerticalScrollBar().addAdjustmentListener( new AdjustmentListener()
{
/**
* detect user fiddling with the scroller
*/
public void adjustmentValueChanged( AdjustmentEvent e )
{
userBusyScrolling = e.getValueIsAdjusting();
}
} );
scroller.getVerticalScrollBar().setValue( 0 );
scroller.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
contentPane.add( scroller );
jFrame.setSize( 270, 120 );
jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
jFrame.validate();
jFrame.setVisible( true );
}
} );
}
}