Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: Image rotation part 2 Date: Tue, 30 Jun 2015 20:17:41 -0400 Organization: A noiseless patient Spider Lines: 49 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 1 Jul 2015 00:19:17 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8e164d158183579609bf09837dee5210"; logging-data="16082"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TkdUHI4PGwCa9+ttPOh81f/bRI5vmPxo=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 In-Reply-To: Cancel-Lock: sha1:thwPzMg5P7d443i6Riw3OqviN6w= Xref: csiph.com comp.lang.java.programmer:31905 On 06/30/2015 07:36 PM, Knute Johnson wrote: I changed the all caps to mixed case just to see. Yep, pretty vertical text is hard. > import java.awt.*; > import java.awt.event.*; > import javax.swing.*; > > public class test4 extends JComponent { > private final String message = "VERTICAL TEXT"; > private final int width = 20; > private final int height = 220; > > public test4() { > setFont(new Font("Monospaced",Font.BOLD,16)); > setPreferredSize(new Dimension(width,height)); > } > > public void paintComponent(Graphics g2d) { > Graphics2D g = (Graphics2D)g2d; > g.setColor(Color.BLACK); > g.fillRect(0,0,width,height); > g.setColor(Color.WHITE); > char[] chars = message.toCharArray(); > FontMetrics metrics = g.getFontMetrics(); > double charHeight = metrics.getHeight() * 0.7; > g.translate( > (width - metrics.charWidth(' '))/2.0, > (height - charHeight * chars.length)/2.0 + charHeight); > for (int i=0; i g.drawChars(chars,i,1,0,0); > g.translate(0,charHeight); > } > } > > public static void main(String... args) { > EventQueue.invokeLater(() -> { > JFrame f = new JFrame(); > f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); > f.add(new test4(),BorderLayout.CENTER); > f.pack(); > f.setVisible(true); > }); > } > } > >