• 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

JfileChooser

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello . I have a desktop app the via Jlist I attempt to open files I placed in
the windows file system. I can manipulate the JFileChooser Dialog enough to
dispaly the files in the dir that I wish to open. However,when I click open nothing
happens. I am running my app using Netbeans and have yet to jar the app and run it
alone. I noticed that in another application that is running without neatbeans that when I use The JfileChooser it displays a Windows window (FileChooser) and the files
can be opened normally. My application in Neatbeans displays a JfileChooser that
does not look like the windows system FileChooser.

How can I open my files with this JfileChooser running in Netbeans?
When I select the .txt file to open it does not open it . it will show the JFileChooser again. see output : thanks
I need to open NotePad.txt files and .doc files with word!
thanks



[output:]
CLASS
class FlashCardListSelectionHandler implements ListSelectionListener {:
--> in public FlashCardListSelectionHandler(javax.swing.event.ListSelectionEvent[ source=javax.swing.DefaultListSelectionModel 24600185 ={0} firstIndex= 0 lastIndex= 0 isAdjusting= false ]){ var:(ListSelectionEvent e)<--
: C:\Users\Steves\.targetFolders\admin_\admin\Note Folder\JFileChooser\open file\flashCard\openAFile.txt: systemDir:

--> in public void TargetFoldersAction.actionPerformed(flashCardChoiceBtn) var: (String actionCommand, String selectionName)<--

--> in private static File getDirectoryChoice( owner.getName() , C:\Users\Steves\.targetFolders\admin_\admin\Note Folder\JFileChooser\open file\flashCard\openAFile.txt , open file) var: (Component owner,String defaultDir,String title)<--

[/output]













 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Howerton wrote:
How can I open my files with this JfileChooser running in Netbeans?



What do you mean by "open" the file?

Do you want to display its contents in your Java app?

Do you want to open the file in the application that's bound to the file extension? E.g., if the user clicks a .doc file, open that in Word?

Something else?

If you read the docs for JFileChooser, I suspect you'll find that its job is only to present a graphical widget in which to select a file or directory, and then return to the caller which file or directory was selected. I doubt it says anything about "opening" the file.
 
Steve Howerton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At the time I wrote the question I did not see the difference. Thank you for pointing out what it is I actually need to do. I would love to be able to have the file selected in the JFileChooser. My DesktopApp button action Knows where the file is. Depending on the button it will know it should be looking for a the .txt or the .doc extention.

I would prefer to write the universal class not dependent on the event but to have java tell the operating system to open the file using a program dependent on the extention. Then I will be able to open *.txt with notpad and .doc with Word. at least. To open other extentions would be awesome though.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what the java.awt.Desktop class is for.
 
Steve Howerton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did not know that . way cool I am on it. Do you have some leads on some professionally written code examples?
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Howerton wrote: Do you have some leads on some professionally written code examples?


I won't speak for everybody but in the day I would have been fired for sharing any proprietary code. I can't even see MY OWN code from that company any more.

Your best bet is always a good search engine to jump start it and then see where you run into problems.
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Howerton wrote:
I noticed that in another application that is running without neatbeans that when I use The JfileChooser it displays a Windows window (FileChooser) and the files
can be opened normally. My application in Neatbeans displays a JfileChooser that
does not look like the windows system FileChooser.



It is because you are using the default Java's look and feel. Switch to system look and feel and the dialog will look like Windows dialog.
 
Nam Ha Minh
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Howerton wrote:did not know that . way cool I am on it. Do you have some leads on some professionally written code examples?


Have a look at the Desktop.open() method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic