[4161] in java-interest
clipRect
daemon@ATHENA.MIT.EDU (Elliotte Rusty Harold)
Tue Dec 12 16:04:40 1995
From: "Elliotte Rusty Harold" <elliotte@blackstar.com>
To: java-interest@java.sun.com
Date: Tue, 12 Dec 1995 14:25:42 EST
Reply-To: elliotte@blackstar.com
X-Confirm-Reading-To: elliotte@blackstar.com
I'd like to write a text string in my applet. That's easy. However
the string is quite long and I only want to write that part of the
string that fits into a particular rectangle. This rectangle is not
identical to the Applet's rectangle. It is smaller. i.e. it is
contained in the applet rectangle. That's hard.
If it's not clear what I'm doing, I'm essentially duplicating the
applet at the top of http://www.cnet.com/
The sensible way to do this sems to be to set the clipRect to the
area I want to draw in before drawing the string. There are two
problems with this:
1. When I do that the string seems not to be drawn at all
2. There seems to be no way to RESET the clipRect. I can use
getClipRect to save the original clipping rectangle. However
according to the documentation clipRect takes the intersection of the
rectangle and the current clipping area. Thus it seems impossible to
make the clipping area bigger.
Here's my paint method.
left, right, bottom and top are class variables that define the
rectangle in which I want to clip to. The call to drawRect is there
so I can make sure that the coordinates I'm giving to clipRect really
are clipping the rectangle I think they are. Based on the rectangle
that is drawn, that seems to be the case. Can anyone spot my mistake?
public void paint(Graphics g) {
Rectangle r;
g.drawImage(background, 0, 0, this);
g.setColor(Color.white);
FontMetrics fm = g.getFontMetrics();
restart = (restart==0)? fm.stringWidth(message) : restart;
oldx = (oldx <= left - restart)? right : oldx - shiftleft;
r = g.getClipRect();
g.drawRect(left,top,right-left,bottom-top);
g.clipRect(left,top,right-left,bottom-top);
g.drawString(message, oldx, (bottom + top + fm.getHeight())/2);
g.clipRect(r.x, r.y, r.width, r.height);
}
Any suggestions?
--
Elliotte Rusty Harold Black Star Publishing Co., Inc.
elliotte@blackstar.com 116 East 27th Street
elharo@shock.njit.edu NY NY 10016
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com