import
java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.border.LineBorder;
/** */ /**
* Created at 2006-7-20 13:01:25<br>
* 可选择描画的线边框
*/
@SuppressWarnings( " serial " )
public class OptionalLineBorder extends LineBorder ... {
private final int LEFT = 0x1;
private final int RIGHT = 0x2;
private final int TOP = 0x4;
private final int BOTTOM = 0x8;
private int paintWay = 0xF;
public OptionalLineBorder(Color color) ...{
super(color);
}
public OptionalLineBorder(Color color, boolean top, boolean left, boolean bottom, boolean right) ...{
this(color);
paintTop(top);
paintLeft(left);
paintBottom(bottom);
paintRight(right);
}
public void setColor(Color color) ...{
if (color != null)
super.lineColor = color;
}
public void paintLeft(boolean b) ...{
paintSide(LEFT, b);
}
public boolean isPaintLeft() ...{
return isPaintSide(LEFT);
}
public void paintRight(boolean b) ...{
paintSide(RIGHT, b);
}
public boolean isPaintRight() ...{
return isPaintSide(RIGHT);
}
public void paintTop(boolean b) ...{
paintSide(TOP, b);
}
public boolean isPaintTop() ...{
return isPaintSide(TOP);
}
public void paintBottom(boolean b) ...{
paintSide(BOTTOM, b);
}
public boolean isPaintBottom() ...{
return isPaintSide(BOTTOM);
}
private void paintSide(int side, boolean b) ...{
if (b) ...{
paintWay |= side;
} else ...{
paintWay &= ~side;
}
}
private boolean isPaintSide(int side) ...{
return (paintWay & side) == side;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) ...{
Color oldColor = g.getColor();
g.setColor(lineColor);
if (isPaintTop()) ...{
g.drawLine(x, y, width, y);
}
if (isPaintLeft()) ...{
g.drawLine(x, y, x, height);
}
if (isPaintBottom()) ...{
g.drawLine(x, y + height - 1, width, y + height - 1);
}
if (isPaintRight()) ...{
g.drawLine(x + width - 1, y, x + width - 1, height);
}
g.setColor(oldColor);
}
}
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.border.LineBorder;
/** */ /**
* Created at 2006-7-20 13:01:25<br>
* 可选择描画的线边框
*/
@SuppressWarnings( " serial " )
public class OptionalLineBorder extends LineBorder ... {
private final int LEFT = 0x1;
private final int RIGHT = 0x2;
private final int TOP = 0x4;
private final int BOTTOM = 0x8;
private int paintWay = 0xF;
public OptionalLineBorder(Color color) ...{
super(color);
}
public OptionalLineBorder(Color color, boolean top, boolean left, boolean bottom, boolean right) ...{
this(color);
paintTop(top);
paintLeft(left);
paintBottom(bottom);
paintRight(right);
}
public void setColor(Color color) ...{
if (color != null)
super.lineColor = color;
}
public void paintLeft(boolean b) ...{
paintSide(LEFT, b);
}
public boolean isPaintLeft() ...{
return isPaintSide(LEFT);
}
public void paintRight(boolean b) ...{
paintSide(RIGHT, b);
}
public boolean isPaintRight() ...{
return isPaintSide(RIGHT);
}
public void paintTop(boolean b) ...{
paintSide(TOP, b);
}
public boolean isPaintTop() ...{
return isPaintSide(TOP);
}
public void paintBottom(boolean b) ...{
paintSide(BOTTOM, b);
}
public boolean isPaintBottom() ...{
return isPaintSide(BOTTOM);
}
private void paintSide(int side, boolean b) ...{
if (b) ...{
paintWay |= side;
} else ...{
paintWay &= ~side;
}
}
private boolean isPaintSide(int side) ...{
return (paintWay & side) == side;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) ...{
Color oldColor = g.getColor();
g.setColor(lineColor);
if (isPaintTop()) ...{
g.drawLine(x, y, width, y);
}
if (isPaintLeft()) ...{
g.drawLine(x, y, x, height);
}
if (isPaintBottom()) ...{
g.drawLine(x, y + height - 1, width, y + height - 1);
}
if (isPaintRight()) ...{
g.drawLine(x + width - 1, y, x + width - 1, height);
}
g.setColor(oldColor);
}
}
试一试就知道了.
可以选择边的边框, 不知道大家使用的多不多, 反正我是经常要用. 所以自己写了一个.