openjdk/jdk · warning · CannotDrawException
ERROR: Cannot print with the current font size. Use smaller
Error message
ERROR: Cannot print with the current font size. Use smaller font size.
What it means
CannotDrawException (CANT_FIT_PRINT variant) from the same grid-fitting check as [18], but on the printing path: the printable page area cannot fit a single glyph cell at the current font size, so printing the range is impossible. Selected by the isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW ternary.
Source
Thrown at src/demo/share/jfc/Font2DTest/FontPanel.java:784
maxDescent = fm.getMaxDescent();
if (maxAscent == 0) maxAscent = 10;
if (maxDescent == 0) maxDescent = 5;
if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
/// Give slight extra room for each character
maxAscent += 3;
maxDescent += 3;
gridWidth = fm.getMaxAdvance() + 6;
gridHeight = maxAscent + maxDescent;
if ( force16Cols )
numCharAcross = 16;
else
numCharAcross = ( w - 10 ) / gridWidth;
numCharDown = ( h - 10 ) / gridHeight;
canvasInset_X = ( w - numCharAcross * gridWidth ) / 2;
canvasInset_Y = ( h - numCharDown * gridHeight ) / 2;
if ( numCharDown == 0 || numCharAcross == 0 )
throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
if ( !isPrinting )
resetScrollbar( verticalBar.getValue() * numCharAcross );
}
else {
maxDescent += fm.getLeading();
canvasInset_X = 5;
canvasInset_Y = 5;
/// gridWidth and numCharAcross will not be used in this mode...
gridHeight = maxAscent + maxDescent;
numCharDown = ( h - canvasInset_Y * 2 ) / gridHeight;
if ( numCharDown == 0 )
throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
/// If this is text loaded from file, prepares the LineBreak'ed
/// text layout at this point
if ( textToUse == FILE_TEXT ) {
if ( !isPrinting )View on GitHub (pinned to 88dfb74bbe)
Solutions
- Reduce the font size before printing.
- In the print/page setup dialog, choose larger paper or the orientation that maximizes usable area.
- Print in a mode other than the full grid (e.g. the one-glyph view) if the range must stay large.
Defensive patterns
Strategy: validation
Validate before calling
// before printing: check the page fits at least one glyph cell
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
int usableW = (int) pf.getImageableWidth();
int usableH = (int) pf.getImageableHeight();
int cellW = fm.getMaxAdvance() + 6, cellH = fm.getMaxAscent() + fm.getMaxDescent() + 3;
if (usableW < cellW || usableH < cellH)
JOptionPane.showMessageDialog(frame, "Font size too large for the page; reduce it before printing."); Try / catch
try {
fontPanel.print();
} catch (CannotDrawException e) {
// printing path: abort the print job cleanly with a user-facing message
job.cancel();
JOptionPane.showMessageDialog(frame, e.getMessage());
} catch (PrinterException e) {
logger.error("print failed", e);
} Prevention
- Derive the print font size from PageFormat.getImageableWidth()/Height(), not from the screen canvas.
- Offer a print preview so oversize fonts are caught before the print dialog.
- Handle CannotDrawException in Printable.print() implementations and return Printable.NO_SUCH_PAGE instead of throwing.
When it happens
Trigger: Printing from Font2DTest while the font size is too large for the page dimensions, or the printer/page setup (small paper, landscape/portrait mismatch) yields a page too narrow for one column or too short for one row.
Common situations: Printing a test range at 72pt+ font sizes; page setup changed to a small paper size; printer margins consuming nearly the whole page.
Related errors
- ERROR: Cannot fit text with the current font size. Resize th
- ERROR: drawBytes cannot handle characters beyond 0x00FF. Sel
- Directory 'New folder' exists
- Cannot create directory
AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14).
Data as JSON: /api/errors/3e04d75bf5c385c8.
Report an issue: GitHub.