NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
sindhughanti
Joined: 12 Apr 2012 Posts: 2
|
Posted: Wed Apr 25, 2012 7:22 am Post subject: Adding a File Chooser |
|
|
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.
|
Posted: Wed Apr 25, 2012 10:44 am Post subject: Adding a File Chooser |
|
|
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
|
Posted: Thu Apr 26, 2012 5:40 am Post subject: Re: Adding a File Chooser |
|
|
| 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.
|
|
| Back to top |
|
 |
|
|
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
|
|