DevFaqEditorHowToGetMimeTypeFromDocumentOrJTextComponent

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