Advertisement
rohitmehra

Untitled

Dec 17th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // Demonstrate JScrollPane.
  2. import java.awt.*;
  3. import javax.swing.*;
  4. /*
  5. <applet code="JScrollPaneDemo" width=300 height=250>
  6. </applet>
  7. */
  8. public class JScrollPaneDemo extends JApplet {
  9. public void init() {
  10. try {
  11. SwingUtilities.invokeAndWait(
  12. new Runnable() {
  13. public void run() {
  14. makeGUI();
  15. }
  16. }
  17. );
  18. } catch (Exception exc) {
  19. System.out.println("Can't create because of " + exc);
  20. }
  21. }
  22. private void makeGUI() {
  23. // Add 400 buttons to a panel.
  24. JPanel jp = new JPanel();
  25. jp.setLayout(new GridLayout(20, 20));
  26. int b = 0;
  27. for(int i = 0; i < 20; i++) {
  28. for(int j = 0; j < 20; j++) {
  29. jp.add(new JButton("Button " + b));
  30. ++b;
  31. }
  32. }
  33. // Create the scroll pane.
  34. JScrollPane jsp = new JScrollPane(jp);
  35. // Add the scroll pane to the content pane.
  36. // Because the default border layout is used,
  37. // the scroll pane will be added to the center.
  38. add(jsp, BorderLayout.CENTER);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement