• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't set the Location of FileDialog

 
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:



 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all.
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic