open dialog box for file chooice

Seventeen Stars

open dialog box for file chooice

hi,
I've to let the choice to user for a file !
So I've tried a simple JFrame with JfileChooser object in a routine call by tjavaflex ...
But I haven't got the time to choice anything Smiley Happy
The frame still open a very short time to disappear ...
problem of thread !??
I'm not enought java coder to find the reason why !!
here the code :

public class FileChooser extends JFrame implements ActionListener{
private JButton bouton = null;
private JPanel panel = null;
private String thePath = null;

public FileChooser(){
panel = new JPanel();
bouton = new JButton();

panel.setLayout(new FlowLayout());
bouton.addActionListener(this);
this.setVisible(true);
this.setSize(new Dimension(400,200));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
JFileChooser chooser = new JFileChooser();
File theFile = null;

if(source == bouton){
int returnVal = chooser.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION){
theFile = chooser.getSelectedFile();
}
}

thePath = theFile.toURI().toString();
}

public String getPath(){
return thePath;
}
}


Hope it's not too long !
Why frame close just as it open !??
thanks for your help or suggestion


Accepted Solutions
One Star

Re: [resolved] open dialog box for file chooice

Use component tJavaFlex.
Under Advanced settings enter: import javax.swing.JFileChooser;
Under Basic settings you can add code like:
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);

All Replies
Seventeen Stars

Re: [resolved] open dialog box for file chooice

any idea so !?
I've tested by launching job like a script (.sh) ... but no more time to hope clicling on anything Smiley Happy
stay and wait for any suggestion (except do not Smiley Happy
++
Seventeen Stars

Re: [resolved] open dialog box for file chooice

try with JOPtionPanel ( have a look on wich class is used on tMsgBox ) in a routines !
Can have a dialog box .... and still open
Just have to add a jfilechooser ...!!
more just play with Talend than work with it ! Smiley Happy
One Star

Re: [resolved] open dialog box for file chooice

Use component tJavaFlex.
Under Advanced settings enter: import javax.swing.JFileChooser;
Under Basic settings you can add code like:
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
Seventeen Stars

Re: [resolved] open dialog box for file chooice

hi
and thanks for your reply.
On the other hand there is a excellent and helpfully component on Talend Exchange.
Regards
laurent