package new1;
import javax.swing.*;
public class New1 {
JFrame f = new JFrame("demo");
JPanel p = new JPanel();
JLabel l = new JLabel("one");
JLabel la = new JLabel("two");
JTextField t = new JTextField();
JTextField ta = new JTextField();
JScrollPane sc = new JScrollPane(p); // scrollbar with panel as constructor.
New1() {
f.add(p); // adding panel o the frame
p.setVisible(true);
p.setLayout(null);
p.setSize(1400, 900);
l.setBounds(10, 50, 100, 20); // setting dimension of labels
la.setBounds(10, 100, 100, 20);
t.setBounds(50, 100, 100, 20); //setting dimension of Textfields
tx.setBounds(50, 50, 100, 20);
p.add(l);
p.add(t);
p.add(la);
p.add(ta);
p.add(tx);
f.setLayout(null);
f.setVisible(true);
f.setSize(1400, 900);
sc.setSize(1350, 700); //setting size of scrollpane
sc.setVisible(true);
p.add(sc); // adding to the panel
}
public static void main(String[] args) {
new New1();
}
}
Here I am adding some label to the JPanel
and want to make this panel scrollable so please help. I am adding scroll pane with panel as constructor so the I can make panel as scrollable but I failed to do.