Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jfilechooser hangs

Status
Not open for further replies.

puremm

Technical User
Oct 30, 2006
23
GB
Hi - not sure if this is the right forum - but

Ive written a small applet ans singed it to select a few files and put them in a list . All initated by java script calls.
The trouble is as soon as the jfilechooser dialog is shown the applet freezes for up to 10 mins maybe more ?

I've downloaded the latest jdk and jre -- any help is gratefuly received. I get the same effect using IE7 and firefox

import java.net.*;
import java.io.*;
import java.awt.*;
import java.lang.String.*;
import java.beans.*;
import javax.swing.*;
import java.util.List;



public class PictDeskUploader extends JApplet //implements ActionListener
{
public static final long serialVersionUID = 1L;
private DefaultListModel listModel; // We need a model to adjust the list
public JList pictFileList; // the Jlist object that will hold the list of files
Container contentpane; // used to reference where the list will be placed
public JFileChooser fc; // file chooser
private File[] files; // Array to hold the file chooser results

public void init ()
{
//evt.start();
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

fc = new JFileChooser();

contentpane = this.getContentPane();
contentpane.setLayout(new FlowLayout());
listModel = new DefaultListModel();
pictFileList = new JList(listModel);
pictFileList.setSelectedIndex(0);
pictFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
contentpane.add(new JScrollPane(pictFileList));
}catch(Exception e){
e.printStackTrace();
}
}


public int addFiles()
{
int i; //array loop counter

String fname ;
fc.setMultiSelectionEnabled(true); // Allow for multiple selections
fc.showOpenDialog (this); // Show the file chooser dialog to the user
files=fc.getSelectedFiles(); // Load the file array with the current selected files
//evt.start();
for ( i = 0; i < files.length; i++) { //loop through the array of files and only add if we havent got it already
fname=files.getPath() ;
if (pictFileList.getModel().getSize() > 0 )
{
if ( pictFileList.getNextMatch(fname, 0, javax.swing.text.Position.Bias.Forward) == -1 )
listModel.addElement ( fname );
} else
listModel.addElement ( fname );
}
// File Add files
return 0;
}
public int deleteFiles()
{
int i; //array loop counter // File remove code
if (pictFileList.getModel().getSize() > 0 ){ // only if more than 1 file
for(i = 0; i < pictFileList.getModel().getSize(); i++) {
int index = pictFileList.getSelectedIndex();
listModel.remove(index);
}
}
return 0;
}

}
 
I'd try setting the initial path of JFileChooser to a known location. Otherwise, it may be slow accesing the filesystem as the Windows explorer is sometimes, specially if there are network drives.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top