OnJava8-Examples/ui/Borders.java

41 lines
1.2 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// ui/Borders.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-06-15 17:47:35 -07:00
// Different Swing borders.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import static onjava.SwingConsole.*;
2015-06-15 17:47:35 -07:00
public class Borders extends JFrame {
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 Borders() {
setLayout(new GridLayout(2,4));
add(showBorder(new TitledBorder("Title")));
add(showBorder(new EtchedBorder()));
add(showBorder(new LineBorder(Color.BLUE)));
add(showBorder(
new MatteBorder(5,5,30,30,Color.GREEN)));
add(showBorder(
new BevelBorder(BevelBorder.RAISED)));
add(showBorder(
new SoftBevelBorder(BevelBorder.LOWERED)));
add(showBorder(new CompoundBorder(
new EtchedBorder(),
new LineBorder(Color.RED))));
}
public static void main(String[] args) {
run(new Borders(), 500, 300);
}
2015-09-07 11:44:36 -06:00
}