• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFileChooser urgent help needed !!!  RSS feed

 
Anamika Singh
Ranch Hand
Posts: 67
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using the save dialog of the JFileChooser .I want the filename text field of the file chooser to be populated with a name specified by me ie "test.txt" as happens in word applications.However when the user browses through the directories the name in this field automatically changes to the current file directory selection .The name should be changable only if explicitly typed in the text field.How do i achieve this functionality..
Thanks in advance
[ September 03, 2002: Message edited by: Anamika Singh ]
 
Zhao Fu Qiang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// hope this can help you!
JFileChooser chooser = new JFileChooser();
chooser.addPropertyChangeListener(new MyChangeListener());
class MyChangeListener implements PropertyChangeListener {

public void propertyChange(PropertyChangeEvent e) {
String name = e.getPropertyName();
if (name.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
File dir = (File)e.getNewValue();
((JFileChooser)e.getSource()).setSelectedFile(new File(dir, getCodeFileName()));
}
}
}
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
zfq
Welcome to the JavaRanch! Please adjust your display name to meet
the JavaRanch Naming Policy. You can change it here.
Thanks!
and welcome to the JavaRanch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!