Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Using File Chooser Under NetBeans (http://www.velocityreviews.com/forums/t619291-using-file-chooser-under-netbeans.html)

Agent Smith 06-09-2008 02:57 PM

Using File Chooser Under NetBeans
 

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. :]

Nigel Wade 06-09-2008 04:03 PM

Re: Using File Chooser Under NetBeans
 
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

Andrew Thompson 06-09-2008 04:31 PM

Re: Using File Chooser Under NetBeans
 
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.

Daniele Futtorovic 06-09-2008 07:58 PM

Re: Using File Chooser Under NetBeans
 
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"

Agent Smith 06-09-2008 11:10 PM

Re: Using File Chooser Under NetBeans
 
Eric Sosman <Eric.Sosman@sun.com> 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

Mark Space 06-09-2008 11:41 PM

Re: Using File Chooser Under NetBeans
 
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.

Andrew Thompson 06-29-2008 04:36 PM

Re: Using File Chooser Under NetBeans
 
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.



All times are GMT. The time now is 10:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.