DevFaqEditorHowToGetMimeTypeFromDocumentOrJTextComponent

(Difference between revisions)
m (How to get mime type from Document or JTextComponent?)
 
Line 22: Line 22:
--------
--------
-
Applies to: NetBeans 6.0, the algorithm in <tt>NbEditorUtilities.getMimeType(JTextComponent)</tt>
+
Applies to: NetBeans 6.x, the algorithm in <tt>NbEditorUtilities.getMimeType(JTextComponent)</tt>
-
works fine in 5.0 and 5.5, but the method is not public.<br>
+
works fine in 5.0 and 5.5, but the method is not public.
-
Platforms: All<br>
+
 
 +
Platforms: All
 +
 
See also: [http://www.netbeans.org/download/dev/javadoc/org-netbeans-modules-editor/index.html Editor Module API]
See also: [http://www.netbeans.org/download/dev/javadoc/org-netbeans-modules-editor/index.html Editor Module API]

Current revision as of 14:07, 16 June 2010

How to get mime type from Document or JTextComponent?

WARNING: 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

Not logged in. Log in, Register

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