Monday, March 17, 2008

JFileChooser setLocation

I was working on my project and my requirement was to have my openDialog set to a location based on the location of another frame. There is a method called setLocation in JFileChooser that should do, but it doesnot do what it is supposed to do and thus reported as a bug at Sun Bug Database There was an alternate solution that was proposed. the solution is to extend the JFileChooser class and create a class that overrides the createDialog method of the JFileChooser Class. Here we should create a dialog and set the properties to this dialog like the resizing, locations etc. and later use this dialog in showOpenDialog method that we use to start the dialog. The extended class overview is present at javadoc- JFileChooser Recaping it again.
  • Creating the class as specified in the documentation with all the required properties set to the dialog within the createDialog method.
  • creating the object of this class and calling the createDialog method
  • Using the showOpenDialog of JFileChooser using the syntax
int returnVal = openWin.showOpenDialog(dialog);
Where dialog is the JDialog that is returned from the createDialog method.

No comments: