Re: Font Resize
"Joseph Gruber" <joseph.gruber@gmail.com> wrote in message
news:1182615312.656754.113320@p77g2000hsh.googlegroups.com...
Hi all -- I'm new to Java programming but I'm trying to write a
program that emulates a terminal (e.g. DOS). I'm using the NetBeans
IDE and I'm looking for any suggestions on how to have the font resize
when the window is resized. Basically so that a specific number of
"lines" (20) would be in the window.
About 10 years ago now (whew! has it been that long?) I was tasked with
writing an IBM 3270 mainframe terminal emulator in Java. We were using AWT
at the time, but not that much has changed when you're doing this kind of
application. Our screen size was 24 rows x 80 columns. We used a fixed-pitch
font (monospace). We listened to the component resize event.
On each size event, we calculated the largest font that would fit into the
available space (vertical and horizontal), by iterating through the font
sizes starting at 1 point, and creating a new font, looking at the font
metrics (advance and height + descent, IIRC). When the font got too big, we
went back to the previous point size, and used that one. We never found a
more efficient way to do this, but it was actually fast enough. The screen
and the font would resize in real time as the user dragged the window
border.