# User Interfaces with a ControlPanel¶

The ControlPanel represents a container for GUI components, providing a flexible text editor-like layout manager. It allows the programmer to add components and to lay out them in the mathlet as easy as writing a text: the ControlPanel’s height will be divided upon all lines where each of them can have a different horizontal alignment (left, right and center). Their height will be determined by the preferred sizes of their child components.

The ControlPanel is a base functionality of the BaseApplet and all of its extending classes. In most cases it is positioned under the canvases (except for the NoCanvasApplet: there it fills the whole vertical space). It can be accessed through

BaseApplet.getControlPanel()


or used indirectly by one of the delegate methods defined in BaseApplet. These delegaters are named after their implementations in the ControlPanel..

It is possible to create a new ControlPanel-instance (e.g. in a standalone applet or in another user interface component) via new ControlPanel().

## Layout Mechanism¶

At the begin (means no object has been added yet) a "line pointer" starts at the first line and adds all following components to it. A line will be terminated by a line break. The pointer will then jump to the second line.

Note that line alignments can only be done for the current row.

It is possible to use tabstops and other space holders for a more exact positioning.

## Method Summary¶

• add(JComponent) – adds a component to the actual line’s end
• addControl(JComponent) – same as add(JComponent)
• addText(String) – adds a TextPanel with the given text
• addText(String, Color) – adds a TextPanel with the given text and color
• addImage(String) – adds an image with the given file location
• insertLineBreak() – jumps to the next line
• insertLineBreak(int) – jumps int lines downwards
• insertTab() – inserts a single tabstop
• insertTab(int) – inserts int tabstops
• insertHSpace(int) – inserts a place holder with int pixels width
• insertVSpace(int) – inserts a place holder with int pixels height
• setLeftAlignment(), setCenterAlignment(), setRightAlignment() – sets left/center/right alignment of the current and all following lines
• setScrollable(boolean) – sets whether the ControlPanel should be scrollable
• getCurrentLine() – returns the container for the current line
• getLine(int n) – returns the container for the n-th line

Add picture from clipboard (Maximum size: 500 MB)