NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Adding a File Chooser

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
sindhughanti



Joined: 12 Apr 2012
Posts: 2

PostPosted: Wed Apr 25, 2012 7:22 am    Post subject: Adding a File Chooser Reply with quote

Hi,
I followed the tutorial from the netbeans site (http://netbeans.org/kb/docs/java/gui-filechooser.html) on adding a file chooser to a Java application. The example explains opening only .txt files. I now want to open .odt files. I inserted the following code, but when I open the odt file, only junk characters open in the text area.


Code:
class MyCustomFilter extends javax.swing.filechooser.FileFilter {
        @Override
        public boolean accept(File file) {
            // Allow only directories, or files with ".txt" extension
            return file.isDirectory() || file.getAbsolutePath().endsWith(".odt");
        }
        @Override
        public String getDescription() {
            // This description will be displayed in the dialog,
            // hard-coded = ugly, should be done via I18N
            return "Text documents (*.odt)";
        }
    }


Please help!
Thanks
Back to top
Artur Rataj
Posted via mailing list.





PostPosted: Wed Apr 25, 2012 10:44 am    Post subject: Adding a File Chooser Reply with quote

In either case, you just get the file's contents. But, txt files contain a plain text, and odt files contain an encoded text. What you see in the latter case is the encoded text.

So you need to decode the contents of an odt file, before putting it into a text widget. It can be done using http://api.openoffice.org/.


Artur
Back to top
sindhughanti



Joined: 12 Apr 2012
Posts: 2

PostPosted: Thu Apr 26, 2012 5:40 am    Post subject: Re: Adding a File Chooser Reply with quote

Artur Rataj wrote:
In either case, you just get the file's contents. But, txt files contain a plain text, and odt files contain an encoded text. What you see in the latter case is the encoded text.

So you need to decode the contents of an odt file, before putting it into a text widget. It can be done using http://api.openoffice.org/.


Artur


Thank you very much. I now understand the difference between these files. However, I am not sure how to proceed in using the APIs. Please help!
Back to top
Artur Rataj
Posted via mailing list.





PostPosted: Fri Apr 27, 2012 6:35 am    Post subject: Adding a File Chooser Reply with quote

Perhaps this will work https://blogs.oracle.com/prasanna/entry/openoffice_parser_extracting_text_from
Or, there is a tool you could call from java http://dag.wieers.com/home-made/unoconv/
I have never used any of this.. If they do not work, I would suggest asking on javaranch or perhaps on the openoffice forums.

Cheers,
Artur
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo