Use Canvas with ScrollPane in swing.
In this section, you will study how to scroll the drawing on canvas. For this, we have used class Canvas which extends the class JPanel. The method setSize() resizes the component by calling the method getPreferredSize() of Component class which returns the dimension object showing the component's preferred size. The class Ellipse2D is used to draw a circle.
Following code adds a scrollpane on canvas:
|getContentPane().add(new JScrollPane(new Canvas()));|
The package javax.swing implements a class JScrollPane which provides the scrollable view of the component.
Here is the code of ScrollPaneOnCanvas.java
Output will be displayed as:
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: December 15, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles