Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #27437
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "John B. Matthews" <nospam@nospam.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Drawstring() and mirror printing. |
| Date | Sat, 01 Feb 2014 20:19:26 -0500 |
| Organization | The Wasteland |
| Lines | 40 |
| Message-ID | <lck6et$o6s$1@dont-email.me> (permalink) |
| References | <da2c2292-8afa-4993-af35-49fa23a58e12@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sun, 2 Feb 2014 01:19:25 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="d17dee34624b7b363488e8f2f4ab0076"; logging-data="24796"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Lxi0mzG3J/+ADh8ONYhX3fAEZV2rnF4o=" |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
| In-Reply-To | <da2c2292-8afa-4993-af35-49fa23a58e12@googlegroups.com> |
| Cancel-Lock | sha1:8Kz5W3xg357LTHvB81YphYcKPkM= |
| Xref | csiph.com comp.lang.java.programmer:27437 |
Show key headers only | View raw
On 2/1/14, 5:34 PM, mariuszpietrzak73@gmail.com wrote:
>
> Please help me to [resolve] issue. I have to print mirror image of string. I [tried] to use AffineTransform and scale. but it didn't work well. Maybe have you any idea to do this?
>
As an alternative to Stefan Ram delightful example, you can alter the
graphics context's transform to invert through the desired axis. The
example below uses scale(1, -1) to create a vertical reflection:
private static class MirrorPanel extends JPanel {
private static final int SZ = 42;
private static final String s = "Hello";
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setFont(getFont().deriveFont(42f));
g2d.drawString(s, SZ, SZ);
g2d.drawLine(SZ, SZ,
SZ + g2d.getFontMetrics().stringWidth(s), SZ);
g2d.scale(1, -1);
g2d.drawString(s, SZ, -SZ);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(SZ * 5, SZ * 2);
}
}
See also this related example due to Daniele Futtorovic:
<http://groups.google.com/group/comp.lang.java.help/browse_frm/thread/2d6db5d6d6739b22>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Drawstring() and mirror printing. mariuszpietrzak73@gmail.com - 2014-02-01 14:34 -0800
Re: Drawstring() and mirror printing. "John B. Matthews" <nospam@nospam.invalid> - 2014-02-01 20:19 -0500
Re: Drawstring() and mirror printing. Silvio <silvio@internet.com> - 2014-02-02 23:14 +0100
Re: Drawstring() and mirror printing. mariuszpietrzak73@gmail.com - 2014-02-03 07:49 -0800
Re: Drawstring() and mirror printing. Roedy Green <see_website@mindprod.com.invalid> - 2014-02-03 09:16 -0800
csiph-web