Java/Swing JFC/BorderFactory — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 06:46, 1 июня 2010
Содержание
- 1 BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), BorderFactory.createMatteBorder(-1, -1, -1, -1, icon))
- 2 BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder())
- 3 BorderFactory.createEmptyBorder
- 4 BorderFactory.createEmptyBorder(10, 10, 10, 10)
- 5 BorderFactory.createEtchedBorder: create Etched Border
- 6 BorderFactory.createEtchedBorder: LOWERED EtchedBorder
- 7 BorderFactory.createLineBorder: create line border
- 8 BorderFactory.createLoweredBevelBorder
- 9 BorderFactory.createMatteBorder(2, 5, 2, 5, Color.BLUE)
- 10 BorderFactory.createRaisedBevelBorder
- 11 BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Title Lowered Etched Border")
- 12 BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE), "Title Line Border with color")
- 13 BorderFactory.createTitledBorder("Title Border")
- 14 Creating a Compound Border
- 15 Creating and Setting a line Border from BorderFactory
- 16 Creating and Setting a Lowered BevelBorder from BorderFactory
- 17 Creating and Setting a MatteBorder from BorderFactory
- 18 Creating and Setting an Empty Border from BorderFactory
- 19 Creating and Setting an EtchedBorder from BorderFactory
- 20 Creating and Setting a Raised BevelBorder from BorderFactory
BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), BorderFactory.createMatteBorder(-1, -1, -1, -1, icon))
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
ImageIcon icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage("matte.gif"));
simplePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createLineBorder(Color.red), BorderFactory.createMatteBorder(-1, -1, -1, -1, icon)));
simplePanel.add(new JLabel("Examples"), JLabel.CENTER);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder())
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
simplePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()));
simplePanel.add(new JLabel("Examples"), JLabel.CENTER);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createEmptyBorder
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
JLabel emptyBorderLabel = new JLabel("Empty Border", JLabel.CENTER);
emptyBorderLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
simplePanel.add(emptyBorderLabel);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createEmptyBorder(10, 10, 10, 10)
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
simplePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JLabel titleLabel = new JLabel("TITLE BORDERS", JLabel.CENTER);
titleLabel.setForeground(Color.red.darker());
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createEtchedBorder: create Etched Border
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(1, 1, 5, 5));
JLabel etchedRasBorderLabel = new JLabel("Raised Etched Border", JLabel.CENTER);
etchedRasBorderLabel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
simplePanel.add(etchedRasBorderLabel);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createEtchedBorder: LOWERED EtchedBorder
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
JLabel etchedLowBorderLabel = new JLabel("Lowered Etched Border", JLabel.CENTER);
etchedLowBorderLabel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
simplePanel.add(etchedLowBorderLabel);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createLineBorder: create line border
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
JLabel lineBorderLabel = new JLabel("Line Border", JLabel.CENTER);
lineBorderLabel.setBorder(BorderFactory.createLineBorder(Color.black));
simplePanel.add(lineBorderLabel);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createLoweredBevelBorder
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
JLabel bevelLowBorderLabel = new JLabel("Lowered Bevel Border", JLabel.CENTER);
bevelLowBorderLabel.setBorder(BorderFactory.createLoweredBevelBorder());
simplePanel.add(bevelLowBorderLabel);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createMatteBorder(2, 5, 2, 5, Color.BLUE)
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
simplePanel.setBorder(BorderFactory.createMatteBorder(2, 5, 2, 5, Color.BLUE));
simplePanel.add(new JLabel("Examples"), JLabel.CENTER);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createRaisedBevelBorder
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
JLabel bevelRasBorderLabel = new JLabel("Raised Bevel Border", JLabel.CENTER);
bevelRasBorderLabel.setBorder(BorderFactory.createRaisedBevelBorder());
simplePanel.add(bevelRasBorderLabel);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Title Lowered Etched Border")
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
simplePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory
.createEtchedBorder(EtchedBorder.LOWERED), "Title Lowered Etched Border"));
simplePanel.add(new JLabel("Examples"), JLabel.CENTER);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLUE), "Title Line Border with color")
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
simplePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory
.createLineBorder(Color.BLUE), "Title Line Border with color"));
simplePanel.add(new JLabel("Examples"), JLabel.CENTER);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
BorderFactory.createTitledBorder("Title Border")
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
public class Main extends JFrame {
public Main() {
JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
simplePanel.setBorder(BorderFactory.createTitledBorder("Title Border"));
simplePanel.add(new JLabel("Examples"), JLabel.CENTER);
add(simplePanel);
}
public static void main(String[] argv) {
Main borderFactoryDemo = new Main();
borderFactoryDemo.setVisible(true);
borderFactoryDemo.pack();
}
}
Creating a Compound Border
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
public class Main {
public static void main(String[] argv) {
LineBorder border1 = new LineBorder(Color.red);
TitledBorder border2 = new TitledBorder("asdf");
Border newBorder = BorderFactory.createCompoundBorder(border1, border2);
JButton component = new JButton("button");
component.setBorder(newBorder);
}
}
Creating and Setting a line Border from BorderFactory
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;
public class Main {
public static void main(String[] argv) {
LineBorder lineBorder = (LineBorder)BorderFactory.createLineBorder(Color.black);
JLabel component = new JLabel("label");
component.setBorder(lineBorder);
}
}
Creating and Setting a Lowered BevelBorder from BorderFactory
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
public class Main {
public static void main(String[] argv) {
BevelBorder loweredBevelBorder = (BevelBorder)BorderFactory.createLoweredBevelBorder();
JLabel component = new JLabel("label");
component.setBorder(loweredBevelBorder);
}
}
Creating and Setting a MatteBorder from BorderFactory
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.border.MatteBorder;
public class Main {
public static void main(String[] argv) {
ImageIcon icon = new ImageIcon("image.gif");
MatteBorder matteBorder = (MatteBorder)BorderFactory.createMatteBorder(-1, -1, -1, -1, icon);
JLabel component = new JLabel("label");
component.setBorder(matteBorder);
}
}
Creating and Setting an Empty Border from BorderFactory
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.EmptyBorder;
public class Main {
public static void main(String[] argv) {
EmptyBorder emptyBorder = (EmptyBorder) BorderFactory.createEmptyBorder();
JLabel component = new JLabel("label");
component.setBorder(emptyBorder);
}
}
Creating and Setting an EtchedBorder from BorderFactory
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.EtchedBorder;
public class Main {
public static void main(String[] argv) {
EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();
JLabel component = new JLabel("label");
component.setBorder(etchedBorder);
}
}
Creating and Setting a Raised BevelBorder from BorderFactory
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
public class Main {
public static void main(String[] argv) {
BevelBorder raisedBevelBorder = (BevelBorder)BorderFactory.createRaisedBevelBorder();
JLabel component = new JLabel("label");
component.setBorder(raisedBevelBorder);
}
}