Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/fltk/fltk/llms.txt

Use this file to discover all available pages before exploring further.

Fl_Box

Header: FL/Fl_Box.H The Fl_Box widget is the simplest FLTK widget - it displays a box and optionally a label. While it cannot receive events or user interaction, it’s extremely useful for:
  • Displaying static text labels
  • Creating decorative frames around other widgets
  • Acting as a spacer or resizable placeholder
  • Drawing background panels

Constructor

Fl_Box(int x, int y, int w, int h, const char *label = 0);
Fl_Box(Fl_Boxtype box, int x, int y, int w, int h, const char *label);
Parameters:
  • x, y - Position relative to parent window
  • w, h - Width and height in pixels
  • label - Optional text to display (default: no label)
  • box - Box type (border/background style)

Key Properties

Controls the visual appearance of the box border and background.Default: FL_NO_BOX (invisible)Common box types:
  • FL_NO_BOX - No border or background (invisible)
  • FL_FLAT_BOX - Flat colored rectangle
  • FL_UP_BOX - Raised 3D border
  • FL_DOWN_BOX - Depressed 3D border
  • FL_BORDER_BOX - Simple thin border
  • FL_THIN_UP_BOX - Thin raised border
  • FL_THIN_DOWN_BOX - Thin depressed border
Fl_Box *box = new Fl_Box(10, 10, 100, 50, "Label");
box->box(FL_UP_BOX);  // Make it visible with raised border
The text displayed inside or near the box.
box->label("Status: Ready");
box->labelsize(16);
box->labelcolor(FL_BLUE);
box->labelfont(FL_HELVETICA_BOLD);
Sets the background color of the box.
box->color(FL_RED);
box->color(fl_rgb_color(200, 220, 240));  // Custom RGB
Controls how the label is positioned relative to the box.
box->align(FL_ALIGN_CENTER);     // Center (default)
box->align(FL_ALIGN_LEFT);       // Left-aligned
box->align(FL_ALIGN_TOP);        // Above box
box->align(FL_ALIGN_INSIDE);     // Force inside

Examples

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main() {
  Fl_Window *win = new Fl_Window(300, 200, "Box Example");
  
  // Simple text label with frame
  Fl_Box *label = new Fl_Box(50, 50, 200, 30, "Welcome to FLTK!");
  label->box(FL_UP_BOX);
  label->labelsize(16);
  label->labelfont(FL_HELVETICA_BOLD);
  
  win->end();
  win->show();
  return Fl::run();
}

Common Use Cases

Title Displays

Use Fl_Box for section headers and titles in your UI.
Fl_Box *title = new Fl_Box(0, 0, 400, 40, "Settings Panel");
title->box(FL_FLAT_BOX);
title->color(FL_DARK_BLUE);
title->labelcolor(FL_WHITE);
title->labelsize(18);
title->labelfont(FL_HELVETICA_BOLD);

Status Bars

Display application status or information at window bottom.
Fl_Box *statusbar = new Fl_Box(0, 370, 600, 30);
statusbar->box(FL_THIN_DOWN_BOX);
statusbar->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
statusbar->label(" Line 1, Col 1");

Decorative Panels

Create visual separators and grouped sections.
Fl_Box *panel = new Fl_Box(10, 50, 280, 200);
panel->box(FL_ENGRAVED_BOX);
panel->color(FL_BACKGROUND2_COLOR);

Image Display

Show images using Fl_Box with image() method.
Fl_PNG_Image *img = new Fl_PNG_Image("logo.png");
Fl_Box *imgbox = new Fl_Box(50, 50, 200, 150);
imgbox->image(img);

Visual Description

An Fl_Box appears as a rectangular region that can have various border styles:
  • FL_NO_BOX: Completely invisible, only label may show
  • FL_FLAT_BOX: Solid colored rectangle with no border
  • FL_UP_BOX: Appears raised with 3D shading effect
  • FL_DOWN_BOX: Appears recessed/pressed into the window
  • FL_BORDER_BOX: Simple thin black outline
  • FL_ENGRAVED_BOX: Looks carved into surface
  • FL_EMBOSSED_BOX: Looks raised from surface

Important Notes

Fl_Box widgets do not respond to events - they cannot be clicked, focused, or receive keyboard input. Use Fl_Button or other interactive widgets if you need user interaction.
The default constructor creates an invisible box with FL_NO_BOX. You must call box() to make it visible, or use the alternate constructor that accepts a box type.
Fl_Box is commonly used as the resizable() widget for Fl_Group and Fl_Window to control resize behavior without visible widgets.
  • Fl_Button - Interactive clickable version
  • Fl_Output - Display-only text field with input styling
  • Fl_Group - Container widget (can also display boxes)

Reference

See source file: FL/Fl_Box.H