Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: FileDialog with JFrame

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question FileDialog with JFrame

    Hello everybody,

    I want to open a file choose dialog within my swing application. My layout is a JPanel within a JFrame (or subclasses of it) and i want to open an AWT FileDialog because i read it would look more native than the JFileChooser on a mac (is this true?). So for creating the FileDialog i need a awt.Frame as parent. But how can i get an awt Frame from my JFrame? Is it possible?

    Thanks,
    Nigi


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: FileDialog with JFrame

    Yes, FileDialog has more of a native look and feel on a mac relative to the JFileChooser. JFrame extends Frame, so just pass this to the constructor.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FileDialog with JFrame

    Thanks,

    my problem was that somehow the getParent() method didn't work properly. It returned me a JPanel instead a JFrame, so i had to write a method setFrame() to pass it the frame. But it works now.

    But then there is another problem:
    Is it true that the setFilenameFilter method has never been implemented for the FileDialog? What a shame. Then I think I have to stick to the not so fancy JFileChooser

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: FileDialog with JFrame

    Quote Originally Posted by nigi10 View Post
    Thanks,

    my problem was that somehow the getParent() method didn't work properly. It returned me a JPanel instead a JFrame, so i had to write a method setFrame() to pass it the frame. But it works now.
    As it should. Content 'added' to a JFrame is added to the content pane of the frame (a JPanel).

    Is it true that the setFilenameFilter method has never been implemented for the FileDialog? What a shame. Then I think I have to stick to the not so fancy JFileChooser

    See the API for FileDialog

Similar Threads

  1. [SOLVED] Drawing on JFrame
    By kbarrett1989 in forum AWT / Java Swing
    Replies: 3
    Last Post: October 31st, 2010, 03:41 AM
  2. Print out a JFrame
    By ellias2007 in forum AWT / Java Swing
    Replies: 8
    Last Post: June 17th, 2010, 06:15 AM
  3. JFrame Edit
    By n00b123 in forum AWT / Java Swing
    Replies: 1
    Last Post: May 19th, 2010, 08:23 PM
  4. JPanel in JFrame
    By maele in forum AWT / Java Swing
    Replies: 2
    Last Post: March 8th, 2010, 04:12 AM
  5. JFrame help
    By Uden in forum AWT / Java Swing
    Replies: 0
    Last Post: August 14th, 2009, 01:37 PM