wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Can't set the Location of FileDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't set the Location of FileDialog

Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

Here is my program and the setLocation() method of FileDialog in my program does not make any changes it always starts with location 0,0:



Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

FileDialog is an AWT component where as JFrame and JButton are Swing. Bad idea to mix those two.
Check out JFileChooser. It is a Swing substitute for FileDialog, which is centered automatically to the parent frame.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
A FileDialog is a stand-alone component, so mixing is probably not that critical, but JFileChooser would be better.

unfortunately (in 1.6), it has the same problem, unless you do this


Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

If you use the JFileChooser#showXXXDialog(Component parent) you need not go through the hassle of setting the location.
Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

I don't want to use JFileChooser because FileDialog has a nice look(file and folder icons ) than JFileChooser and in JFileChooser all files and folders have same color. Is there any other way to set its Location.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19675
    
  18

Maneesh Godbole wrote:If you use the JFileChooser#showXXXDialog(Component parent) you need not go through the hassle of setting the location.

You can achieve the same for every Window subclass by calling setLocationRelativeTo(parent).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> If you use the JFileChooser#showXXXDialog(Component parent) you need not go through the hassle of setting the location.

yes, but if you don't want the filechooser centered over the parent (and, personally, it's the best place for it),
then setLocation() should work (it used to work, but not in 1.6)
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I don't want to use JFileChooser because FileDialog has a nice look(file and folder icons ) than JFileChooser and in JFileChooser all files and folders have same color.
> Is there any other way to set its Location.

the problem seems to be in 1.6, so, FileDialog, being one of the older awt component classes,
you should start googling and/or search sun's bug database, or just accept (possibly modify) JFileChooser's look
Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

Thanks to all.
 
 
subject: Can't set the Location of FileDialog