Wednesday, September 5, 2012

Border examples of created by BorderFactory

It's more border examples of created by BorderFactory.

Border examples of created by BorderFactory


package javatestswing;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaTestSwing {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(runJFrameLater);
    }
    
    static Runnable runJFrameLater = new Runnable() {

        @Override
        public void run() {
            MyJFrameWin myjFrameWindow;
            myjFrameWindow = new MyJFrameWin();
            myjFrameWindow.setVisible(true);
        }
    
    };
    
    public static class MyJFrameWin extends JFrame{
        
        public MyJFrameWin(){
            this.setTitle("java-buddy.blogspot.com");
            this.setSize(350, 450);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            this.setLayout(new FlowLayout());
            
            this.add(createBorderedPanel(BorderFactory.createRaisedBevelBorder(), 
                    "createRaisedBevelBorder()"));
            
            this.add(createBorderedPanel(BorderFactory.createBevelBorder(BevelBorder.LOWERED),
                    "createBevelBorder(BevelBorder.LOWERED)"));
            
            this.add(createBorderedPanel(BorderFactory.createBevelBorder(BevelBorder.RAISED),
                    "createBevelBorder(BevelBorder.RAISED)"));
            
            this.add(createBorderedPanel(BorderFactory.createCompoundBorder(
                    BorderFactory.createBevelBorder(BevelBorder.RAISED), 
                    BorderFactory.createBevelBorder(BevelBorder.LOWERED)),
                    "createCompoundBorder(..RAISED, ..LOWERED)"));
            
            this.add(createBorderedPanel(BorderFactory.createEtchedBorder(), 
                    "createEtchedBorder()"));
            
            this.add(createBorderedPanel(
                    BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), 
                    "createEtchedBorder(EtchedBorder.LOWERED)"));
            
            this.add(createBorderedPanel(
                    BorderFactory.createEtchedBorder(EtchedBorder.RAISED), 
                    "createEtchedBorder(EtchedBorder.RAISED)"));
            
            this.add(createBorderedPanel(
                    BorderFactory.createEtchedBorder(
                        Color.lightGray, 
                        Color.yellow), 
                    "createEtchedBorder(Color.lightGray, Color.yellow)"));
            
            this.add(createBorderedPanel(
                    BorderFactory.createLineBorder(Color.red), 
                    "createLineBorder(Color.red)"));
            
            this.add(createBorderedPanel(
                    BorderFactory.createLineBorder(Color.blue, 5), 
                    "createLineBorder(Color.blue, 5)"));

            this.add(createBorderedPanel(BorderFactory.createDashedBorder(null), 
                    "createDashedBorder(null)"));
            
        }
    }
    
    private static JPanel createBorderedPanel(Border b, String name){
        JLabel label = new JLabel(name);
        
        JPanel panel = new JPanel();
        panel.setBorder(b);
        panel.add(label);
        
        return panel;
    }
}


No comments:

Post a Comment