Flex Border : Border « Swing JFC « Java






Flex Border

   

//   FlexBorder
//
//   Copyright (C) by Andrea Carboni.
//   This file may be distributed under the terms of the LGPL license.
//


import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.border.Border;

public class FlexBorder implements Border
{
  public static final int NONE        = 0;
  public static final int TOP_LINE    = 1;
  public static final int BOTTOM_LINE = 2;
  public static final int RECT        = 3;
  
  private Insets insets = new Insets(0,0,0,0);
  private Color  color  = Color.blue;
  private int    type   = RECT;
  
  //---------------------------------------------------------------------------

  public FlexBorder()
  {
  }
  
  //---------------------------------------------------------------------------
  
  public FlexBorder(Color c, int t)
  {
    color = c;
    type  = t;
  }

  //---------------------------------------------------------------------------

  public void setColor(Color c)
  {
    color = c;
  }
  
  //---------------------------------------------------------------------------
  
  public void setType(int t)
  {
    type = t;
  }
    
  //---------------------------------------------------------------------------
  //---
  //---   Border interface methods
  //---
  //---------------------------------------------------------------------------

  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
  {
    g.setColor(color);
    
    switch(type)
    {
      case TOP_LINE:    g.drawLine(x,y, x+width-1, y);
                  break;

      case BOTTOM_LINE: g.drawLine(x,y+height-1, x+width-1, y+height-1);
                  break;
        
      case RECT:      g.drawRect(x, y, width-1, height-1);
                  break;
    }
  }

  //---------------------------------------------------------------------------

  public Insets getBorderInsets(Component c)
  {
    return insets;
  }

  //---------------------------------------------------------------------------

  public boolean isBorderOpaque() { return false; }
}

//

   
    
    
  








Related examples in the same category

1.Border Demo Border Demo
2.Different Swing bordersDifferent Swing borders
3.demonstrate the custom CurvedBorder classdemonstrate the custom CurvedBorder class
4.An example of the MatteBorder classAn example of the MatteBorder class
5.A simple demonstration of the LineBorder class built with rounded cornersA simple demonstration of the LineBorder class built with rounded corners
6.An example of using a titled border on a labelAn example of using a titled border on a label
7.Borders with a BevelBorder used on JLabels as a highlightBorders with a BevelBorder used on JLabels as a highlight
8.MatteBorder DemoMatteBorder Demo
9.TitledBorder DemoTitledBorder Demo
10.Custom Border SampleCustom Border Sample
11.How to create the borderHow to create the border
12.Solid border button border 3D borderSolid border button border 3D border
13.Oval borderOval border
14.Border of all kindsBorder of all kinds
15.EtchedBorderEtchedBorder
16.Red Green BorderRed Green Border
17.TitledBorderTitledBorder
18.TitledBorder 3TitledBorder 3
19.BevelBorder 2BevelBorder 2
20.Icon MatteBorderIcon MatteBorder
21.Soft BevelBorderSoft BevelBorder
22.Another TitledBorder 1Another TitledBorder 1
23.BevelBorderBevelBorder
24.EmptyBorderEmptyBorder
25.LineBorder DemoLineBorder Demo
26.CompoundBorder DemoCompoundBorder Demo
27.Adding a Title to a Border
28.Create a title border from another border
29.Change border text Justification alignment style
30.Bottom Border
31.Right border
32.Rectangle border
33.Set title position