Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't set the Location of FileDialog

 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11185
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11185
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the JFileChooser#showXXXDialog(Component parent) you need not go through the hassle of setting the location.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic