Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Using File Chooser Under NetBeans

Reply
Thread Tools

Using File Chooser Under NetBeans

 
 
Agent Smith
Guest
Posts: n/a
 
      06-09-2008

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. :]
 
Reply With Quote
 
 
 
 
Nigel Wade
Guest
Posts: n/a
 
      06-09-2008
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/tutor...lechooser.html


--
Nigel Wade
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-09-2008
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.
 
Reply With Quote
 
Daniele Futtorovic
Guest
Posts: n/a
 
      06-09-2008
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"
 
Reply With Quote
 
Agent Smith
Guest
Posts: n/a
 
      06-09-2008
Eric Sosman <(E-Mail Removed)> 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/tutor...ts/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
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      06-09-2008
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.
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-29-2008
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SAX and file chooser steve_marjoribanks@hotmail.com Java 7 02-17-2006 04:49 PM
URL file chooser Robert M. Gary Java 2 01-31-2006 05:36 PM
File Chooser... =?Utf-8?B?Unlv?= ASP .Net 2 12-02-2005 03:47 PM
Date & Time chooser for java 1.1 - using only the mouse to select time & date Chris Berg Java 0 10-27-2003 10:59 PM
Windows NT and java 1.4.2 file chooser problem Szymon Madejczyk Java 2 09-15-2003 06:50 AM



Advertisments