In this Java AWT Video, we will use the AWT ScrollPane to scroll the Grid of Checkboxes. The Check Boxes are created in a panel and then given to scroll pane.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
package AwtDemoPkg; import java.awt.Checkbox; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GridLayout; import java.awt.Panel; import java.awt.ScrollPane; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; public class FrameWindow extends Frame implements WindowListener { public FrameWindow(String FrameTitle) { //Display the Frame Window super(FrameTitle); setSize(300, 150); setLocation(100,100); addWindowListener(this); //Sample 01: Create a grid of Checkboxes Panel CheckBoxPanel = new Panel(); CheckBoxPanel.setLayout(new GridLayout(30,30)); for (int col=1; col<31; col++) { for (int row=1; row<31; row++) { Checkbox chk = new Checkbox(col + "." + row ); CheckBoxPanel.add(chk); } } //Sample 02: Add Panel to a Scroll Panel ScrollPane scp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS); scp.setSize(500,250); scp.add(CheckBoxPanel); //Sample 03: Add ScrollPane to Frame Window add(scp); } public void windowOpened(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowClosing(WindowEvent e) { this.dispose(); } } |
Categories: AWT-Tube