0

I want to add Scroll in this Jframe. I Have Tried different codes but none of them help. Please Help me to add scroll in this JFrame. This is simple code. I have tried JPanel but it is also not working.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;

    class classes extends JFrame implements ActionListener
    {
    JLabel l1,l2,l3,l4,l5,l6,l7,l8;
    classes()
    {
    con=getContentPane();
    setTitle("Scroll");
    setLayout(null);
    setSize(150,150);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    l1=new JLabel("1");
    l2=new JLabel("2");
    l3=new JLabel("3");
    l4=new JLabel("4");
    l5=new JLabel("5");
    l6=new JLabel("6");
    l7=new JLabel("7");
    l8=new JLabel("8");

    l1.setBounds(50,50,100,30);
    l2.setBounds(50,100,100,30);
    l3.setBounds(50,150,100,30);
    l4.setBounds(50,200,100,30);
    l5.setBounds(50,250,100,30);
    l6.setBounds(50,300,100,30);
    l7.setBounds(50,350,100,30);
    l8.setBounds(50,400,100,30);

    add(l1);
    add(l2);
    add(l3);
    add(l4);
    add(l5);
    add(l6);
    add(l7);
    add(l8);
    setVisible(true);
    }
    }
  • [So many duplicate questions/answers!](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:stackoverflow.com+java+add+jscrollpane+to+jframe&*) – Hovercraft Full Of Eels Mar 08 '17 at 17:44
  • 1
    Here's one main problem: `setLayout(null);`. Read the tutorials and learn to use the layout managers. Without them JScrollPanes won't work. – Hovercraft Full Of Eels Mar 08 '17 at 17:44
  • If you want to put your entire window contents in a JScrollPane, you probably need to rethink your layout, and possibly split it up into a JTabbedPane or cards in a CardLayout. – VGR Mar 08 '17 at 21:32

1 Answers1

0

like setContentPane(new JScrollPane(new JPanel())); ?

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66