How to get mime type from Document or JTextComponent?
| The API described here is not official! Check the javadoc for its stability level. |
// Suppose you have javax.swing.text.Document
String mimeType = NbEditorUtilities.getMimeType(document);
// Suppose you have javax.swing.text.JTextComponent
String mimeType = NbEditorUtilities.getMimeType(component);
The method accepting JTextComponent is generally more practical, because
JTextComponent or its subclasses is what you usually have to start with.
Internally the method calls the Document version of itself on the document
loaded in the component and returns its mime type (if it has any assigned). If
the document does not have mime type information attached (and non-Netbeans documents
generally don’t) the method will use the component’s EditorKit to get it.
Applies to: NetBeans 6.x, the algorithm in NbEditorUtilities.getMimeType(JTextComponent)
works fine in 5.0 and 5.5, but the method is not public.
Platforms: All
See also: Editor Module API