JScrollPane on top of everything
In a program I am developing I have a JDialog that pops up and displays a list of files to be deleted. Its achieved by creating a grid of the files and adding them to a panel which is then added to a JScrollPane. The problem is that the scrollpane appears on top of everything. There is a header, the pane, and then two buttons and the buttons are covered up and when you scroll down the pane slides over the header and you have to scroll all the way down to see the buttons. How can I contain the scroll pane within its bounds so that the extra parts are not displayed over everything else? Here is the code for my JDialog, its called using:
Todelete deletewindow;
deletewindow =new Todelete();
deletewindow.setVisible(true);
and the actualy code for the window is:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
publicclass Todeleteextends JDialog{
static String files[];
public Todelete()
{
super(main.window,"Delete Files",true);
final File tardirect =new File(EProperties.destination);
files = tardirect.list();
int j = 0;
for(int i = 0; i < files.length; i++)
{
if(files[i].matches("(?i)PPC.*.txt"))
{
j++;
}
}
int k = 0;
final String filteredfiles[] =new String[j];
for(int i = 0; i < files.length; i ++)
{
if(files[i].matches("(?i)PPC.*.txt"))
{
filteredfiles[k] = files[i];
k++;
}
}
final Checkbox thelist[] =new Checkbox[filteredfiles.length];
System.out.println("TEST");
for(int i = 0; i < files.length; i++)
{
System.out.println(files[i]);
}
JPanel thetop =new JPanel();
JPanel thebody =new JPanel();
JPanel thebottom =new JPanel();
JLabel header;
header =new JLabel(
"<html><h3><i>Delete Old PPC Files</i></h4></html>");
JButton delete =new JButton("Delete");
delete.setToolTipText("Click here to delete the selected files");
delete.addActionListener(new
ActionListener()
{
publicvoid actionPerformed(ActionEvent event)
{
File delfile;
setVisible(false);
for (int i = 0; i < filteredfiles.length; i++)
{
delfile =new File(tardirect +"\\" + filteredfiles[i]);
if(thelist[i].getState() ==true)
{
System.out.println("File to delete: " + delfile.toString());
delfile.delete();
}
}
}
});
JButton cancel =new JButton("Cancel");
cancel.addActionListener(new
ActionListener()
{
publicvoid actionPerformed(ActionEvent event)
{
setVisible(false);
}
});
thebody.setLayout(new GridLayout(filteredfiles.length,1));
for (int i = 0; i < filteredfiles.length; i++)
{
thelist[i] =new Checkbox(filteredfiles[i],null,true);
thebody.add(thelist[i]);
}
JScrollPane scrollpane =new JScrollPane(thebody);
scrollpane.setPreferredSize(new Dimension(200,200));
thetop.add(header);
thebottom.add(delete);
thebottom.add(cancel);
getContentPane().add(thetop,BorderLayout.NORTH);
getContentPane().add(scrollpane,BorderLayout.CENTER);
getContentPane().add(thebottom, BorderLayout.SOUTH);
setSize(250,350);
}
}
Any help would be greatly appreciated.

