In a general graphic interface, if the area to be displayed is not large enough, a scroll bar may appear to facilitate your browsing. In Swing, the main function of JScrollPane is to add a horizontal scroll bar to the displayed content.
Package com. beyole. util; import java. awt. container; import java. io. file; import javax. swing. icon; import javax. swing. imageIcon; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JPanel; import javax. swing. JScrollPane; public class test12 {public static void main (String [] args) {JFrame frame = new JFrame ("Crystal"); // instantiate the form object Container container = frame. getContentPane (); // get the form container String path = "f:" + File. separator + "1.jpg"; Icon icon = new ImageIcon (path); JLabel label = new JLabel (icon); JPanel = new JPanel (); panel. add (label); JScrollPane scrollPane = new JScrollPane (panel, JScrollPane. VERTICAL_SCROLLBAR_ALWAYS, JScrollPane. HORIZONTAL_SCROLLBAR_AS_NEEDED); container. add (scrollPane); frame. setSize (230,120); frame. setLocation (300,200); frame. setVisible (true );}}
Program: