[5389] in java-interest
Re: Separator, border width ???
daemon@ATHENA.MIT.EDU (Amy Fowler)
Wed Feb 7 13:12:54 1996
Date: Wed, 7 Feb 1996 08:04:35 -0800
From: Amy.Fowler@Eng.Sun.COM (Amy Fowler)
To: java-interest@java.Eng.Sun.COM, katsalis@csd.uch.gr
Cc: katsalis@csd.uch.gr
>> is there a way to create a separator, or to put
>> a border around a panel, a canvas etc ..
Yes, I've included a simple Separator object below (note that it
only does "etched in", you might want to make its style a
configurable parameter).
You can also override the panel's paint method and draw your
decorations directly on the panel - they key here is to ensure
that whatever you are drawing isn't obscurred by any of the
panel's children (using Insets is a nice way to do this if you
just want a border).
Regards,
Amy Moore-Fowler
Java Products Group
Sun Microsystems, Inc.
-------------------------------------------------------------------
import java.awt.*;
public class Separator extends Canvas {
public final static int HORIZONTAL = 0;
public final static int VERTICAL = 1;
int orientation;
public Separator(int length, int thickness, int orient) {
super();
orientation = orient;
if (orient == HORIZONTAL) {
resize(length, thickness);
} else { // VERTICAL
resize(thickness, length);
}
}
public void paint(Graphics g) {
int x1, y1, x2, y2;
Rectangle bbox = bounds();
Color c = getBackground();
Color brighter = c.brighter();
Color darker = c.darker();
if (orientation == HORIZONTAL) {
x1 = 0;
x2 = bbox.width - 1;
y1 = y2 = bbox.height/2 - 1;
} else { // VERTICAL
x1 = x2 = bbox.width/2 - 1;
y1 = 0;
y2 = bbox.height - 1;
}
g.setColor(darker);
g.drawLine(x1, y2, x2, y2);
g.setColor(brighter);
if (orientation == HORIZONTAL)
g.drawLine(x1, y2+1, x2, y2+1);
else
g.drawLine(x1+1, y2, x2+1, y2);
}
}
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com