Overview
JSqlEditor is a professional SQL editor component built on RichTextFX with intelligent features including syntax highlighting, autocomplete, real-time validation, and code formatting.Constructor
Properties
Controls whether the editor is read-only
- Default:
false - Editable when
false, read-only whentrue
Controls the editor theme
- Default:
false(light mode) - Automatically switches stylesheets and colors
List of SQL validation errors
- Updated automatically after 400ms debounce
- Each error contains line, column, and message
Core Methods
Text Management
Returns the current SQL text
Alias for
getSql()Alias for
setSql(String)Clears all text from the editor
Formatting & Validation
Formats the SQL text using SqlFormatter
- Applies standard SQL formatting
- Uppercase keywords
- 4-space indentation
- 80-character max column length
- Keyboard shortcut:
Ctrl+Shift+F
Returns observable list of validation errors
Focus & Navigation
Requests focus on the code editor
Selects all text in the editor
Scrolls the editor to the top-left position
Theme
Toggles between light and dark theme
- Switches color scheme instantly
- Updates status bar indicator
Returns current dark mode state
Clipboard
Copies the entire SQL text to system clipboard
Advanced Access
Returns the underlying RichTextFX CodeArea for advanced operations
Cleans up subscriptions and resources
- Call when removing the editor from the scene
- Unsubscribes from reactive streams
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Tab | Insert 4 spaces or accept autocomplete |
Backspace | Smart delete 4 spaces if preceded by indent |
Enter | Smart indent based on previous line |
Ctrl+Space | Trigger autocomplete |
Ctrl+/ | Toggle line comment |
Ctrl+D | Duplicate current line |
Ctrl+Shift+K | Delete current line |
Ctrl+Shift+F | Format SQL |
Auto-Complete
- Triggers automatically after typing 2+ characters
- Includes SQL keywords, data types, and functions
- Navigate with arrow keys, accept with
EnterorTab - Force trigger with
Ctrl+Space
Syntax Highlighting
Supported token types:- Keywords: SELECT, FROM, WHERE, JOIN, etc.
- Data Types: VARCHAR, INTEGER, TIMESTAMP, etc.
- Functions: COUNT, SUM, AVG, COALESCE, etc.
- Strings: Single-quoted literals
- Comments: Line (
--) and block (/* */) - Numbers: Integers, decimals, scientific notation
- Operators:
=,<>,+,-, etc.
Real-Time Validation
- Validates SQL syntax using JSqlParser
- 400ms debounce to avoid performance impact
- Highlights error lines in red
- Shows error count in status bar
- Click error indicator to navigate to first error
SqlError Record
Line number (1-based)
Starting column (0-based)
Ending column (0-based)
Error description in Spanish
Example Usage
Styling
The component uses separate stylesheets for light and dark themes:/css/sql-editor-light.css/css/sql-editor-dark.css
.j-sql-editor- Main container.j-sql-code-area- Code editing area.j-sql-status-bar- Bottom status bar.sql-keyword,.sql-type,.sql-function- Syntax tokens.sql-error-line- Error highlighted lines
Notes
- Built on RichTextFX for high-performance text rendering
- Uses JSqlParser for SQL validation
- Supports PostgreSQL, MySQL, Oracle, SQL Server dialects
- Line numbers are always visible
- Status bar shows cursor position and error count