Hi all,
I was just trying to write a simple prog in which i'm trying to add multiple components to a JPanel and inturn i'm adding that to a JScrollpane. Now the problem i'm facing is when i run the prog i can see the contents of the panel(not all) and i can also see scrollbar but i can't find the knob to move it back and forth please look into my code and help me out.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.*;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneLayout;
import javax.swing.border.LineBorder;
public class AddingToJScrollPane {
static JScrollPane scroll=null; //new JScrollPane(null);
public static void main(String args[]) {
JFrame frame = new JFrame("Tabbed Pane Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel=new JPanel();
panel.setLayout(null);
JButton jButton1 = new JButton();
jButton1.setBounds(50, 500, 70, 30);
panel.add(jButton1);
int inc=0;
for(int i=0;i<=100;i++){
JLabel label = new JLabel("Label");
label.setBounds(10, 10+inc, 70, 30);
panel.add(label);
inc=inc+50;
}
scroll = new JScrollPane (panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setEnabled(true);
scroll.setPreferredSize(new Dimension(100,100));
frame.add(scroll);
scroll.setVisible (true);
frame.setSize(500, 400);
frame.setVisible(true);
}
}
Thanks in advance.