Class PanelOutputStream

java.lang.Object
java.io.OutputStream
noaa.coastwatch.gui.PanelOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class PanelOutputStream extends OutputStream

The PanelOutputStream class extends java.io.OutputStream to display output in a Swing JPanel. The most common use is to create a PanelOutputStream to be used in combination with a java.io.PrintStream object:

   PanelOutputStream panelStream = new PanelOutputStream();
   PrintStream printStream = new PrintStream (panelStream, true);
   JPanel panel = panelStream.getPanel();
   ...
   printStream.println ("Hello, world!");
 

The output stream has a special method getPanel() that retrieves a javax.swing.JPanel object that may be used to display the output. The retrieved JPanel is simply a Swing text area inside a scrollable pane. The text area is set to non-editable.

In general, as output is appended to the text area, the scroll panel scrolls to the bottom so that the new output is visible. To explicitly set the caret position of the text area, you can do something like this:

   PanelOutputStream panelStream = new PanelOutputStream();
   JTextArea textArea = panelStream.getTextArea(); 
   ...
   textArea.setCaretPosition (0);
 

The text area is also useful for setting specific fonts, for example a fixed space font rather than the default proportional space font.

Since:
3.1.7
Author:
Peter Hollemans
  • Constructor Details

    • PanelOutputStream

      public PanelOutputStream()
      Creates a new panel output stream.
  • Method Details

    • getPanel

      public JPanel getPanel()
      Gets the associated output panel.
    • getTextArea

      public JTextArea getTextArea()
      Gets the associated text area.
    • write

      public void write(int b) throws IOException
      Writes the specified byte to this output stream. See the general contract for java.io.OutputStream.write(int).
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b) throws IOException
      Writes b.length bytes from the specified byte array to this output stream. See the general contract for java.io.OutputStream.write(byte[]).
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes len bytes from the specified byte array starting at offset off to this output stream. See the general contract for java.io.OutputStream.write(byte[],int,int).
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • main

      public static void main(String[] argv)
      Tests this class.
      Parameters:
      argv - the array of command line parameters.