DevFaqOutputWindow

How do I create my own tab in the output window and write to it?

NetBeans contains classes that make writing to the output window very simple - you don't have to worry about components, you just get an instance of a thing called InputOutput, which has methods getOut() and getErr() that return OutputStreams. There is a utility class, IOProvider that can supply InputOutput objects - you pass it a string name that should be shown on the output tab, and a boolean (whether or not it should reuse an existing tab with the same name if there is one). So, hello world code for the output window looks like this:

InputOutput io = IOProvider.getDefault().getIO ("Hello", true);
io.getOut().println ("Hello from standard out");
io.getErr().println ("Hello from standard err");  //this text should appear in red
io.getOut().close();
io.getErr().close();

It is important to close the output streams when you are done with them - output is written to a memory mapped file, which cannot be deleted if the stream is still open - and the tab title will remain boldfaced until the streams are closed, which helps indicate to the user that the process has finished.

-- Main.timboudreau - 10 Jun 2006

Note: For platform based applications to correctly use InputOutput and IOProvider an Output Window implementation must be available and enabled. Follow the below steps to be sure you include everything to allow the output window and tabs to be used and shown.

  1. Open your module projects properties. (Right click the project and select properties).
  2. Select libraries
  3. Check to see if 'I/O APIs' is in the dependency list.
  4. If it is not it needs to be added.

To add 'I/O APIs'

  1. Choose 'Add' from 'Module Dependencies'
  2. Select 'I/O APIs' from the list
  3. Press OK

To force 'Output Window' (the implementation of the tabbed output window) to be enabled,

  1. Choose 'Add' from 'Required Tokens'
  2. Pick =org.openide.windows.IOProvider=
  3. Press OK

Note: this shall not be necessary in the current 6.0 trunk version..

Relevent to 6.0: If the dependencies do not show up in the selection list check the 'Module Suite' to make sure they have not been excluded from the platform.

  1. Right click on the module suite
  2. Click Properties
  3. Go to Libraries
  4. Locate the platform 'Clusters and Modules'
  5. Make sure I/O API is checked
  6. Make sure Output Window is checked
  7. Click OK

Hint: It is sometimes helpful to call InputOutput.select() to make sure the tab is made visible in the output window.

See here for a plugin that has a convenient class for all output purposes.

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