Rajan, I tried what you said but it didn't seem to work. I am adding textfields dynamically to the Panel. The problem lies in showing the Vertical scroll bar once the text fields in the JPanel exceeds the Panel's size. The scrolls don't seem to show up. Here is part of my code where the problem might lie.
public Scenario() // Constructor
{
textPanel = new JPanel();
textPanel.setLayout(null);
textPanel.setSize(508, 520);
textPanel.setLocation(10,10);
//..........lines of code
//.............
}
public void addComponent(String text)
{
j = j + 30;
i = i+1;
String lineno = Integer.toString(i) + ".";
field = new JLabel(lineno);
field.setBounds(90,j,20,24);
textPanel.add(field);
if (addline){
content = new JTextField(text);
content.setBounds(108,j,400,24);
content.setBackground(new Color(255,255,255));
textPanel.add(content);
addline = false;
invscenario = false;
}
else if(invscenario) {
content = new JTextField(text);
content.setBounds(108,j,50,24);
content.setEditable(false);
textPanel.add(content);
try{
if (content.getText().length()!= 0)
{
Statement statement1 = conn.createStatement();
String query1 = "SELECT * FROM scenario " + "WHERE scenario_num LIKE '" + text + "'";
rs = statement1.executeQuery(query1);
rs.next();
int recordNumber = rs.getInt(1);
if(recordNumber != 0)
{
labelcontent = new JLabel(rs.getString(3));
labelcontent.setBounds(165,j,100,24);
textPanel.add(labelcontent);
}
}
}// end try
catch(SQLException e)
{
System.out.println(e);
}
invscenario = false;
addline = false;
}
scrollPane = new JScrollPane(textPanel);
scrollPane.add(textPanel);
contentPane.add(scrollPane);
contentPane.repaint();
show();
}