| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| |
| = DevFaqEditorHowToGetMimeTypeFromDocumentOrJTextComponent |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| :keywords: Apache NetBeans wiki DevFaqEditorHowToGetMimeTypeFromDocumentOrJTextComponent |
| :description: Apache NetBeans wiki DevFaqEditorHowToGetMimeTypeFromDocumentOrJTextComponent |
| :toc: left |
| :toc-title: |
| :syntax: true |
| |
| == How to get mime type from `Document` or `JTextComponent`? |
| |
| WARNING: The API described here is not official! Check the javadoc for its |
| stability level. |
| |
| [source,java] |
| ---- |
| |
| // 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: link:http://www.netbeans.org/download/dev/javadoc/org-netbeans-modules-editor/index.html[Editor Module API] |
| |
| == Apache Migration Information |
| |
| The content in this page was kindly donated by Oracle Corp. to the |
| Apache Software Foundation. |
| |
| This page was exported from link:http://wiki.netbeans.org/DevFaqEditorHowToGetMimeTypeFromDocumentOrJTextComponent[http://wiki.netbeans.org/DevFaqEditorHowToGetMimeTypeFromDocumentOrJTextComponent] , |
| that was last modified by NetBeans user Vstejskal |
| on 2010-06-16T14:07:23Z. |
| |
| |
| *NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed. |