A simple applet that shows labels with six different types of border.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | /******************************************************* * MYCPLUS Sample Code - https://www.mycplus.com * * * * This code is made available as a service to our * * visitors and is provided strictly for the * * purpose of illustration. * * * * Please direct all inquiries to saqib at mycplus.com * *******************************************************/ // A simple applet that shows labels with six different types of border. import java.awt.*; import javax.swing.*; import javax.swing.border.Border; public class BorderDemo extends JApplet { public void init() { setBackground(Color.lightGray); getContentPane().setBackground( Color.lightGray ); getContentPane().setLayout( new GridLayout(0,1,7,7) ); make(BorderFactory.createLineBorder(Color.red,2), "BorderFactory.createLineBorder(Color.red,2)"); make(BorderFactory.createMatteBorder(2,2,5,5,Color.red), "BorderFactory.createMatteBorder(2,2,5,5,Color.red)"); make(BorderFactory.createEtchedBorder(), "BorderFactory.createEtchedBorder()"); make(BorderFactory.createRaisedBevelBorder(), "BorderFactory.createRaisedBevelBorder()"); make(BorderFactory.createLoweredBevelBorder(), "BorderFactory.createLoweredBevelBorder()"); make(BorderFactory.createTitledBorder("Title Goes Here"), "BorderFactory.createTitledBorder(\"Title Goes Here\")"); } void make(Border border, String command) { // Make a lable showing the string and with the specified border. // The label will be opaque and will have a light gray background. // The label is added to the applet's content pane. JLabel label = new JLabel(command, JLabel.CENTER); label.setBackground(Color.lightGray); label.setOpaque(true); label.setBorder(border); getContentPane().add(label); } public Insets getInsets() { // Leave a border around the applet where the background // color will show through. return new Insets(7,7,7,7); } } // end class JApplet |