可选边框的Border

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);
 }

}

试一试就知道了.
可以选择边的边框, 不知道大家使用的多不多, 反正我是经常要用. 所以自己写了一个.
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值