Using the new border types in Java 7 - Java Swing

Java examples for Swing:Border

Description

Using the new border types in Java 7

Demo Code

import java.awt.BasicStroke;
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.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;

public class Main extends JFrame {

    public Main() {
        this.setTitle("Example");
        this.setBounds(100, 100, 200, 100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
        //from   ww w  .  j a  v a2s  . co  m
        panel.setBorder(BorderFactory.createRaisedSoftBevelBorder());
        panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1, true));
        panel.setBorder(BorderFactory.createLoweredSoftBevelBorder());        
        panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED));
        panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED));
        panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, Color.lightGray, Color.yellow));
        panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED, Color.lightGray, Color.yellow));
        panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, Color.lightGray, Color.lightGray, Color.white, Color.orange));
        panel.setBorder(BorderFactory.createStrokeBorder(new BasicStroke(1.0f)));
        panel.setBorder(BorderFactory.createDashedBorder(Color.red));
        panel.setBorder(BorderFactory.createDashedBorder(Color.red, 4.0f, 1.0f));
        panel.setBorder(BorderFactory.createDashedBorder(Color.red, 2.0f, 10.0f, 1.0f, true));

        
        this.setLayout(new FlowLayout());

        JButton exitButton = new JButton("Exit");
        panel.add(exitButton);
        this.add(panel);
        
        exitButton.addActionListener(event->System.exit(0));
    }

    public static void main(String[] args) {              
        
        SwingUtilities.invokeLater(() ->{
                Main window = new Main();
                window.setVisible(true);
        });

    }
}

Related Tutorials