import java.awt.*; import java.awt.event.*; public class TextClipTest extends Canvas { static String str; static int numStrs = 300; public TextClipTest() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < numStrs; i++) { sb.append("Text Clip Test"); } str = sb.toString(); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g; g2d.setColor(Color.white); g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.setColor(Color.black); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); g2d.setFont(g2d.getFont().deriveFont(40.0f)); g2d.drawString(str, 10, 150); FontMetrics fm = g2d.getFontMetrics(); System.out.println(fm.stringWidth(str)); } public static void main(String[] args) { /* boolean show = (args.length == 1) && ("-show".equals(args[0])); */ boolean show = false; if (args.length == 1) { try { numStrs = Integer.parseInt(args[0]); } catch (Exception e) {} } TextClipTest test = new TextClipTest(); final Frame frame = new Frame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); } }); frame.add(test); frame.pack(); frame.setSize(600, 600); frame.setVisible(true); if (!show) { try { Thread.sleep(5000); } catch (Exception e) {} frame.dispose(); } } }