FileDocCategorySizeDatePackage
BorderPanel.javaAPI DocExample3549Wed Apr 19 11:19:00 BST 2000None

BorderPanel

public class BorderPanel extends Panel

Fields Summary
protected int
shadow
Panel shadow border width
protected boolean
raised
Panel raised vs depressed look
Constructors Summary
public BorderPanel()

      
        this.raised=true;
    
public BorderPanel(boolean raised)

        this.raised=raised;
    
Methods Summary
public static java.awt.ColoravgColor(java.awt.Color c1, java.awt.Color c2)

    return new Color(
        (c1.getRed()+c2.getRed())/2,
        (c1.getGreen()+c2.getGreen())/2,
        (c1.getBlue()+c2.getBlue())/2
        );
   
public voiddraw3DRect(java.awt.Graphics g, int x, int y, int width, int height, boolean raised)
Draw a 3D Rectangle.

param
g the specified Graphics window
param
x, y, width, height
param
raised - true if border should be painted as raised.
see
#paint

      Color c = g.getColor();
      Color brighter = avgColor(c,Color.white);
      Color darker = avgColor(c,Color.black);


      // upper left corner
      g.setColor(raised ? brighter : darker);
      for (int i=0; i<shadow; i++) {
	  g.drawLine(x+i, y+i, x+width-1-i, y+i);
	  g.drawLine(x+i, y+i, x+i, y+height-1-i);
      }
      // lower right corner
      g.setColor(raised ? darker : brighter);
      for (int i=0; i<shadow; i++) {
	  g.drawLine(x+i, y+height-1-i, x+width-1-i, y+height-1-i);
	  g.drawLine(x+width-1-i, y+height-1-i, x+width-1-i, y+i);
      }
      g.setColor(c);
      // added by rip.
      g.setColor(Color.black);
      g.drawRect(x,y,width+2,height+2);

   
protected voidlayoutParent()
Re-layout parent. Called when a panel changes size etc.

      Container parent = getParent();
      if (parent != null) {
	 parent.doLayout();
      }
   
public voidpaint(java.awt.Graphics g)

        super.paint(g);
        Dimension size = getSize();
        paintBorder(g, size);
    
protected voidpaintBorder(java.awt.Graphics g, java.awt.Dimension size)

      Color c = getBackground();
      g.setColor(c);
      g.fillRect(0, 0, size.width, size.height);
      draw3DRect(g, 0, 0, size.width, size.height, raised);