Overview
TheJDesignCanvas component provides an interactive visual design surface for creating label layouts. It supports:
- Drag-and-drop field placement from sidebar
- Dynamic slot configuration (text lines and barcode area)
- Visual label media with premium styling
- Zoom controls (0.5x to 2.0x)
- Slot reordering via drag-and-drop
- Export design configuration as structured data
The design canvas simulates a physical label media (420x320px) with a white background, soft shadow, and rounded corners for a premium studio look.
Basic Usage
Label Media Configuration
Configure the number of text slots on the label:The barcode area is always added automatically at the end of the label, regardless of the number of text lines configured.
Label Dimensions
The label media has fixed dimensions (JDesignCanvas.java:37-48):- Width: 420px
- Height: 320px
- Padding: 25px
- Spacing: 15px between slots
- Border radius: 16px
- Shadow: Soft drop shadow for depth
Drag and Drop System
The canvas accepts draggable fields from the sidebar:Drop Zones
The canvas has two types of drop zones:Text Slots
Display field data as text labels. Configurable count via
setSupportedLines().Barcode Area
Displays field data as visual barcode representation with vertical lines.
Visual Feedback
Slot States
- Empty Slot
- Hover State
- Filled Slot
Barcode Visualization
When a field is dropped on the barcode area (JDesignCanvas.java:251-276):Visual Example
Visual Example
Zoom Controls
Zoom the canvas between 0.5x and 2.0x:Zoom is applied using JavaFX
Scale transform with the pivot point at the center of the label media for smooth scaling.Export Design Data
Extract the current design configuration:Design Data Structure
Empty slots (not assigned a field) will have
type but no fieldId in the exported data.Reset Canvas
Clear all slots and reset to initial state:Complete Example
Slot Reordering
Slots can be reordered by dragging (JDesignCanvas.java:212-223):Integration with JDraggableField
The canvas is designed to work withJDraggableField components:
JDraggableField.
API Reference
Constructor
Methods
| Method | Return Type | Description |
|---|---|---|
setSupportedLines(int) | void | Set number of text line slots |
zoomIn() | void | Zoom in by 0.1 (max 2.0) |
zoomOut() | void | Zoom out by 0.1 (min 0.5) |
getDesignData() | Map<String, Object> | Export design configuration |
reset() | void | Clear canvas and reset zoom |
Design Data Schema
Styling
The canvas uses these CSS classes:.j-design-canvas- Main container (light gray studio background).label-media- The white label surface.canvas-slot- Individual text slots.barcode-drop-zone- Barcode area.drag-over- Applied during drag hover