Different Swing borders : Border « Swing JFC « Java






Different Swing borders

Different Swing borders
   
// : c14:Borders.java
// Different Swing borders.
// <applet code=Borders width=500 height=300></applet>
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.TitledBorder;

public class Borders extends JApplet {
  static JPanel showBorder(Border b) {
    JPanel jp = new JPanel();
    jp.setLayout(new BorderLayout());
    String nm = b.getClass().toString();
    nm = nm.substring(nm.lastIndexOf('.') + 1);
    jp.add(new JLabel(nm, JLabel.CENTER), BorderLayout.CENTER);
    jp.setBorder(b);
    return jp;
  }

  public void init() {
    Container cp = getContentPane();
    cp.setLayout(new GridLayout(2, 4));
    cp.add(showBorder(new TitledBorder("Title")));
    cp.add(showBorder(new EtchedBorder()));
    cp.add(showBorder(new LineBorder(Color.BLUE)));
    cp.add(showBorder(new MatteBorder(5, 5, 30, 30, Color.GREEN)));
    cp.add(showBorder(new BevelBorder(BevelBorder.RAISED)));
    cp.add(showBorder(new SoftBevelBorder(BevelBorder.LOWERED)));
    cp.add(showBorder(new CompoundBorder(new EtchedBorder(),
        new LineBorder(Color.RED))));
  }

  public static void main(String[] args) {
    run(new Borders(), 500, 300);
  }

  public static void run(JApplet applet, int width, int height) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(applet);
    frame.setSize(width, height);
    applet.init();
    applet.start();
    frame.setVisible(true);
  }
} ///:~



           
         
    
    
  








Related examples in the same category

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