Class TextBox

  • All Implemented Interfaces:
    Direct Known Subclasses:

    public class TextBox
    extends SoAnnotation
    (Preview Feature) Shape node to display a text box in window coordinates.

    Preview Feature means this class is fully supported and can be used in Open Inventor applications. Being tagged as a Preview Feature just means that the implementation is still subject to API changes and adjustments based on feedback from early adopters. Please be also aware that source compatibility might be broken regardless of the Open Inventor compatibility changes policy due to our commitment to bring needed changes to be sure the specifications of this Preview Feature match the expectations of our customers.

    This node displays a text box at a fixed location in the viewer window.

    The position is specified in normalized device coordinates -1 to 1. Horizontal alignmentH and vertical alignmentV can be specified. For example position -0.98, -0.98, 0 with TOP/LEFT alignment (the default) puts a text box in the upper left corner of the window. The text box automatically expands or shrinks when lines of text are added to or deleted from the box. Positioning a text box in the lower left corner creates a sort of 'console' output overlaying the scene. Note that the alignment options control the positioning of the text box. The text can be left, center or right justified inside the box using the alignmentH field.

    In order to have convenient default values for the font properties, by default the font properties are not inherited from the scene graph. By default the text is rendered using an SoText2 node with font name 'Arial:Bold', font size 15 and line spacing 1.1. The application can modify the fontName and fontSize fields or modify text properties directly using the getFontNode() and getTextNode() methods.

    Lighting and picking are disabled. A border can be drawn around the box. Text will be rendered on top of whatever is rendered in the main scene graph. The application can modify the text strings directly, but this class also provides some convenience methods that are very useful. For example, the addLine() method appends a new string to the end of the list.

    The bounding box of this node is ignored, i.e. it does not contribute to an SoGetBoundingBoxAction traversal and it does not affect a "viewAll" call on the camera or viewer.

    File format/default:

    TextBox {

      position 0 0 0
      alignmentH LEFT
      alignmentV TOP
      textAlignH LEFT
      fontName Arial:Bold
      fontSize 15
      border FALSE
      borderColor 1 1 1

    See Also:
    DicomInfo, Magnifier, Gnomon, Ruler
    • Field Detail

      • position

        public SoSFVec3f position
        Position of the text box in normalized screen coordinates (-1 to 1). Default is 0,0,0.
      • fontName

        public SoSFString fontName
        Specify the font name (default is "Arial:Bold"). See for details
      • fontSize

        public SoSFFloat fontSize
        Specify the font size in pixels (default is 15).
      • border

        public SoSFBool border
        Enable drawing a border around the text box (default is false).
      • borderColor

        public SoSFColor borderColor
        Border color (default is 1,1,1).
    • Constructor Detail

      • TextBox

        public TextBox()
    • Method Detail

      • setLine

        public void setLine​(java.lang.String text,
                            int line)
        Set the contents of the specified line of text (convenience method).
      • addLine

        public void addLine​(java.lang.String text)
        Add a line of text at the bottom of the box.
      • getNumLines

        public int getNumLines()
        Get number of lines of text currently in the box