Search code examples
javatexttextfieldjava-canvas

compress text in java if it gets too long


i want to add print functionality to my software, this requires to compress the text not fit them in the textbox (letters should not be shrunk vertically).

is this possible with standard java methods or does someboday know good extensions?

i want to have the text like on the attached picture

Thanks!enter image description here


Solution

  • You can try to override paintComponent() and apply horizontal scale to the Graphics instance

    Graphics2D g2d=(Graphics2D)g;
    AffineTransform old=g2d.getTransform();
    g2d.scale(0.5, 1);
    //paint the text here
    g2d.setTransform(old);