// 
//     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.
//

= DevFaqHowToPrint
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqHowToPrint
:description: Apache NetBeans wiki DevFaqHowToPrint
:toc: left
:toc-title:
:syntax: true

=== Help the Print menu item is disabled!

There are several ways to enable printing for a custom data:

If the data is a Swing component which extends JComponent and shown in a TopComponent, the key PRINT_PRINTABLE with value "Boolean.TRUE" in the component must be set as a client property. See example:

[source,java]
----

    public class MyComponent extends javax.swing.JComponent {
      public MyComponent() {
        ...
        putClientProperty("print.printable", Boolean.TRUE); // NOI18N
      }
      ...
    }
----

The key PRINT_NAME is used to specify the name of the component which will be printed in the header/footer:

[source,java]
----

    putClientProperty("print.name", <name>); // NOI18N
----

If the key is not set at all, the display name of the top component is used by default. The content of the header/footer can be adjusted in the Print Options dialog.

If the size of the custom component for printing differs from visual dimension, specify this with the key PRINT_SIZE:

[source,java]
----

    putClientProperty("print.size", new Dimension(printWidth, printHeight)); // NOI18N
----

If the custom data is presented by several components, all of them can be enabled for print preview. The key PRINT_ORDER is used for this purpose, all visible and printable components are ordered and shown in the Print Preview dialog from the left to right:

[source,java]
----

    putClientProperty("print.order", <order>); // NOI18N
----

If the custom data is presented by another classes, a PrintProvider should be implemented and put in the lookup of the top component where the custom data lives. How to put the Print action on custom Swing tool bar:

[source,java]
----

    public class MyComponent extends javax.swing.JComponent {
      ...
      JToolBar toolbar = new JToolBar();
      // print
      toolbar.addSeparator();
      toolbar.add(PrintManager.printAction(this));
      ...
    }
----

How does Print action from the main menu decide what to print?

At first, the manager searches for PrintProvider in the lookup of the active top component. If a print provider is found, it is used by the print manager for print preview.

Otherwise, it tries to obtain printable components among the descendants of the active top component. All found printable components are passed into the Print Preview dialog. Note that print method is invoked by the manager for preview and printing the component.

If there are no printable components, printable data are retrieved from the selected nodes of the active top component. The Print manager gets EditorCookie from the DataObject of the Nodes. The StyledDocuments, returned by the editor cookies, contain printing information (text, font, color). This information is shown in the print preview. So, any textual documents (Java/C++/Php/... sources, html, xml, plain text, etc.) are printable by default. 

See link:http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-print/org/netbeans/api/print/PrintManager.html[PrintManager] javadoc for details.

=== 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/DevFaqHowToPrint[http://wiki.netbeans.org/DevFaqHowToPrint] , 
that was last modified by NetBeans user Skygo 
on 2013-12-14T17:08:39Z.


*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.
