1 /**2 * Java Swing's jscrollpane panel3 * When setting up the interface, you may experience the display of a larger portion of the content in a smaller container form, which you can use4 * jscrollpane Panel, jscrollpane panel is a panel with scroll bars, is also a container, but often used to decorate a single5 * control, and you cannot use the layout manager. If you need to place multiple controls in the JScrollPane panel, you need to add multiple6 * Control is placed on the JPanel panel, and the JPanel panel is added to the JScrollPane control as a whole control. 7 * 8 * @authorGao9 */Ten PackageCom.gao; One A Importjava.awt.BorderLayout; - - ImportJavax.swing.JFrame; the ImportJavax.swing.JPanel; - ImportJavax.swing.JScrollPane; - ImportJavax.swing.JTextArea; - ImportJavax.swing.border.EmptyBorder; + - Public classJscrollpanedemoextendsjframe{ + PrivateJPanel ContentPane; A PrivateJScrollPane ScrollPane; at PrivateJTextArea TextArea;
- PublicJscrollpanedemo () { -Contentpane=NewJPanel (); -Contentpane.setborder (NewEmptyborder (5,5,5,5)); -Contentpane.setlayout (NewBorderLayout (0,0)); - This. Setcontentpane (ContentPane); inScrollpane=NewJScrollPane (); - Contentpane.add (scrollpane,borderlayout.center); toTextarea=NewJTextArea (); + //Scrollpane.add (TextArea); - Scrollpane.setviewportview (TextArea); the This. Settitle ("Scroll panel use"); * This. Setdefaultcloseoperation (jframe.exit_on_close); $ This. setbounds (100, 100, 250, 200);Panax Notoginseng This. setvisible (true); - } the Public Static voidMain (String []args) { +Jscrollpanedemo example=NewJscrollpanedemo (); A } the}
Reproduced Java Swing JScrollPane (scroll panel) how to use