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.

Sunday, March 9, 2008

GridBag Layout

My actual requirement is the figure shown. I am not really good at swings and was learning it with this application. I was trying various layouts, but none of them helped me to actually get good results for my application, then finally came across grid layout. It has some of the wonderful features like it divides the frame into grids in which it is similar to the grid layout but can also add features like setting the location of the component, filling the component horizontally in the grid or vertically, we can set up the grid width and height. We can change the properties of the grid using the GridBagConstraints class. And later using this object when we are actually adding components to the frame or panel. I am new to swings, this is just a way to share my experiences, any suggestions and changes would be greatly appreciated.