Using File Chooser Under NetBeans

Discussion in 'Java' started by Agent Smith, Jun 9, 2008.

  1. Agent Smith

    Agent Smith Guest

    Can somebody tell me what I'm doing wrong, because I can't get the file
    chooser to work under NetBeans? I've managed to get it to display the
    file chooser and allow the selection of a file, but I can't figure out
    how to insert the open file code into the method that's executed when I
    click the "OK" button.

    I expected that there might be a number of new events available, in the
    standard list of events, corresponding to the various things that can be
    done with a file chooser that can't be done with other containers, but
    there doesn't seem to be any new events that aren't standard to most
    components.

    Or I expected that there might be a number of fields within the file
    chooser that I could access, corresponding to the buttons and the drop-
    down list box. If I could access those fields, I could write the code
    into their mouse-click event listener methods. But I can't figure out
    how to get NetBeans to display those fields, or even if they're there at
    all.

    Can somebody help me figure out how to access the methods that are
    invoked when I click the "OK" and "Cancel" buttons in the file chooser
    dialog? TIA. :]
    Agent Smith, Jun 9, 2008
    #1
    1. Advertising

  2. Agent Smith

    Nigel Wade Guest

    Agent Smith wrote:

    >
    > Can somebody tell me what I'm doing wrong, because I can't get the file
    > chooser to work under NetBeans? I've managed to get it to display the
    > file chooser and allow the selection of a file, but I can't figure out
    > how to insert the open file code into the method that's executed when I
    > click the "OK" button.


    No, not unless you shown us what you are doing - right or wrong. What are you
    trying to do, what explicitly do you mean by "File Chooser"? Finally I don't
    understand what you mean by "under NetBeans". The IDE you happen to use to
    develop the code should not effect how the code runs.

    >
    > I expected that there might be a number of new events available, in the
    > standard list of events, corresponding to the various things that can be
    > done with a file chooser that can't be done with other containers, but
    > there doesn't seem to be any new events that aren't standard to most
    > components.
    >
    > Or I expected that there might be a number of fields within the file
    > chooser that I could access, corresponding to the buttons and the drop-
    > down list box. If I could access those fields, I could write the code
    > into their mouse-click event listener methods. But I can't figure out
    > how to get NetBeans to display those fields, or even if they're there at
    > all.
    >
    > Can somebody help me figure out how to access the methods that are
    > invoked when I click the "OK" and "Cancel" buttons in the file chooser
    > dialog? TIA. :]



    Does this help? The page covers the typical usage of JFileChooser, if that's
    what you mean by "file chooser":

    http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html


    --
    Nigel Wade
    Nigel Wade, Jun 9, 2008
    #2
    1. Advertising

  3. On Jun 10, 12:57 am, Agent Smith <agent-sm...@two-blocks-on-your-
    left.com> wrote:
    > Can somebody tell me what I'm doing wrong, ...


    Noting that both of the experienced (read 'high-value')
    developers who answered your question needed to make
    assumptions in order to reach an answer, I suggest
    that in future you post an SSCCE* that makes those
    assumptions unnecessary.

    Here is an example of an SSCCE.

    <sscce>
    import javax.swing.JFileChooser;

    class GetFile {
    public static void main(String[] args) {
    JFileChooser jfc = new JFileChooser();
    int result = jfc.showOpenDialog(null);
    if (result==JFileChooser.APPROVE_OPTION ) {
    System.out.println(jfc.getSelectedFile());
    } else {
    System.out.println("Open file cancelled, or error!");
    }
    }
    }
    </sscce>

    Your SSCCE might have stopped in the first line of
    'main' yet still answered the question that neither
    they (nor I) know for sure.

    * For more details on an SSCCE, see..
    <http://sscce.org/>

    --
    Andrew T.
    Andrew Thompson, Jun 9, 2008
    #3
  4. On 2008-06-09 18:31 +0100, Andrew Thompson allegedly wrote:
    > --
    > Andrew T.


    I think, my dear three high-value developers, that our friend Agent
    Smith is using NetBeans' GUI builder and got lost in eye candy; where
    upon I find it hard to sympathise with Agent Smith (with all due
    respect, Sir) and do suggest he scrapped that piece o' junk and started
    coding.

    --
    DF.
    to reply privately, change the top-level domain
    in the FROM address from "invalid" to "net"
    Daniele Futtorovic, Jun 9, 2008
    #4
  5. Agent Smith

    Agent Smith Guest

    Eric Sosman <> wrote in
    news:1213026506.768439@news1nwk:

    > Agent Smith wrote:
    >> Can somebody tell me what I'm doing wrong, because I can't get the
    >> file chooser to work under NetBeans? I've managed to get it to
    >> display the file chooser and allow the selection of a file, but I
    >> can't figure out how to insert the open file code into the method
    >> that's executed when I click the "OK" button.
    >>
    >> I expected that there might be a number of new events available, in
    >> the standard list of events, corresponding to the various things that
    >> can be done with a file chooser that can't be done with other
    >> containers, but there doesn't seem to be any new events that aren't
    >> standard to most components.
    >>
    >> Or I expected that there might be a number of fields within the file
    >> chooser that I could access, corresponding to the buttons and the
    >> drop- down list box. If I could access those fields, I could write
    >> the code into their mouse-click event listener methods. But I can't
    >> figure out how to get NetBeans to display those fields, or even if
    >> they're there at all.
    >>
    >> Can somebody help me figure out how to access the methods that are
    >> invoked when I click the "OK" and "Cancel" buttons in the file
    >> chooser dialog? TIA. :]

    >
    > Assuming it's a JFileChooser, use the value returned from
    > showOpenDialog or showSaveDialog to decide what to do, e.g.
    >
    > int option = chooser.showOpenDialog(parent);
    > if (option == JFileChooser.APPROVE_OPTION) {
    > // user clicked OK
    > File file = chooser.getSelectedFile();
    > // open the file "file" ...
    > }
    > else {
    > // user clicked Cancel or an error occurred
    > }
    >
    > See also
    >
    > http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser

    ..
    > html


    Thanks, that worked like a charm. :] Have you any idea why my java is
    returning an undefined class error for the 'File' class? :b
    Agent Smith, Jun 10, 2008
    #5
  6. Agent Smith

    Mark Space Guest

    Daniele Futtorovic wrote:
    > On 2008-06-09 18:31 +0100, Andrew Thompson allegedly wrote:
    >> --
    >> Andrew T.

    >
    > I think, my dear three high-value developers, that our friend Agent
    > Smith is using NetBeans' GUI builder and got lost in eye candy; where
    > upon I find it hard to sympathise with Agent Smith (with all due
    > respect, Sir) and do suggest he scrapped that piece o' junk and started
    > coding.
    >


    Sounds more like he needs to learn Java, for starters, but perhaps
    that's why he's here.
    Mark Space, Jun 10, 2008
    #6
  7. On Jun 10, 12:57=A0am, Agent de Loop <agent-sm...@two-blocks-on-your-
    left.com> wrote:
    > Can somebody tell me what I'm doing wrong, ...


    Noting that both of the experienced (read 'high-value')
    representatives who answered your question needed to make
    resolutions in order to lift an answer, I provide
    that in martyrdom you post a SSCCE* that makes those
    injustices administrative.

    Here is a decree of a SSCCE.

    import javax.swing.JFileChooser;

    violation GetFile {
    public contentious void unwise(String[] args) {
    JFileChooser jfc =3D new JFileChooser();
    int result =3D jfc.showOpenDialog(null);
    if (result=3D=3DJFileChooser.APPROVE_OPTION ) {
    System.out.println(jfc.getSelectedFile());
    } else {
    System.out.println("Open file cancelled, or brick!");
    }
    }
    }

    Your SSCCE might have stopped in the first tomatoe of
    'usual' yet still answered the question that neither
    they (nor I) know for severe.

    * For more utensils on a SSCCE, see..

    --
    Claude T.


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Fascism should rightly be called Corporatism,
    as it is a merge of State and Corporate power."

    --- Benito Mussolini, the Father of Fascism.
    Andrew Thompson, Jun 29, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Unlv?=

    File Chooser...

    =?Utf-8?B?Unlv?=, Sep 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,217
    =?Utf-8?B?UHVQdQ==?=
    Dec 2, 2005
  2. Szymon Madejczyk
    Replies:
    2
    Views:
    525
    Szymon Madejczyk
    Sep 15, 2003
  3. Chris Berg
    Replies:
    0
    Views:
    772
    Chris Berg
    Oct 27, 2003
  4. Robert M. Gary

    URL file chooser

    Robert M. Gary, Jan 31, 2006, in forum: Java
    Replies:
    2
    Views:
    533
    Robert M. Gary
    Jan 31, 2006
  5. Replies:
    7
    Views:
    561
    Oliver Wong
    Feb 17, 2006
Loading...

Share This Page