Java by API/javax.swing.border/TitledBorder — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
- 1 new TitledBorder(Border border, String title)
- 2 new TitledBorder(Border border, String title, int titleJustification, int titlePosition)
- 3 new TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)
- 4 TitledBorder.ABOVE_BOTTOM
- 5 TitledBorder.ABOVE_TOP
- 6 TitledBorder.BELOW_BOTTOM
- 7 TitledBorder.BELOW_TOP
- 8 TitledBorder.BOTTOM
- 9 TitledBorder.CENTER
- 10 TitledBorder.LEFT
- 11 TitledBorder.RIGHT
- 12 TitledBorder: setTitleJustification(int pos)
- 13 TitledBorder: setTitlePosition(int pos)
- 14 TitledBorder.TOP
new TitledBorder(Border border, String title)
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.Border;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.metal.MetalIconFactory;
public class MainClass {
public static void main(String[] a) {
JFrame frame = new JFrame("Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Border thisBorder = BorderFactory.createTitledBorder("Easy");
Icon thatIcon = MetalIconFactory.getFileChooserHomeFolderIcon();
Border thatBorder1 = new MatteBorder(18, 20, 18, 20, thatIcon);
Border thatBorder2 = new TitledBorder(thatBorder1, "Harder");
Font font = new Font("Serif", Font.ITALIC, 12);
Border thatBorder = new TitledBorder(thatBorder2, "Hardest",
TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM, font, Color.RED);
JButton thisButton = new JButton("Easy");
thisButton.setBorder(thisBorder);
JButton thatButton = new JButton("Harder");
thatButton.setBorder(thatBorder);
Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(1, 2));
contentPane.add(thisButton);
contentPane.add(thatButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
new TitledBorder(Border border, String title, int titleJustification, int titlePosition)
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Double Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
topBorder.setTitlePosition(TitledBorder.TOP);
TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom",
TitledBorder.RIGHT, TitledBorder.BOTTOM);
JButton doubleButton = new JButton();
doubleButton.setBorder(doubleBorder);
Container contentPane = frame.getContentPane();
contentPane.add(doubleButton, BorderLayout.CENTER);
frame.setSize(300, 100);
frame.setVisible(true);
}
}
new TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.Border;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.metal.MetalIconFactory;
public class MainClass {
public static void main(String[] a) {
JFrame frame = new JFrame("Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Border thisBorder = BorderFactory.createTitledBorder("Easy");
Icon thatIcon = MetalIconFactory.getFileChooserHomeFolderIcon();
Border thatBorder1 = new MatteBorder(18, 20, 18, 20, thatIcon);
Border thatBorder2 = new TitledBorder(thatBorder1, "Harder");
Font font = new Font("Serif", Font.ITALIC, 12);
Border thatBorder = new TitledBorder(thatBorder2, "Hardest",
TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM, font, Color.RED);
JButton thisButton = new JButton("Easy");
thisButton.setBorder(thisBorder);
JButton thatButton = new JButton("Harder");
thatButton.setBorder(thatBorder);
Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(1, 2));
contentPane.add(thisButton);
contentPane.add(thatButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder.ABOVE_BOTTOM
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Positioned Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder aboveBottomBorder = BorderFactory.createTitledBorder("AboveBottom");
aboveBottomBorder.setTitlePosition(TitledBorder.ABOVE_BOTTOM);
JButton aboveBottomButton = new JButton();
aboveBottomButton.setBorder(aboveBottomBorder);
Container contentPane = frame.getContentPane();
contentPane.add(aboveBottomButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder.ABOVE_TOP
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Positioned Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder aboveTopBorder = BorderFactory.createTitledBorder("AboveTop");
aboveTopBorder.setTitlePosition(TitledBorder.ABOVE_TOP);
JButton aboveTopButton = new JButton();
aboveTopButton.setBorder(aboveTopBorder);
Container contentPane = frame.getContentPane();
contentPane.add(aboveTopButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder.BELOW_BOTTOM
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Positioned Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder belowBottomBorder = BorderFactory.createTitledBorder("BelowBottom");
belowBottomBorder.setTitlePosition(TitledBorder.BELOW_BOTTOM);
JButton belowBottomButton = new JButton();
belowBottomButton.setBorder(belowBottomBorder);
Container contentPane = frame.getContentPane();
contentPane.add(belowBottomButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder.BELOW_TOP
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Positioned Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder belowTopBorder = BorderFactory.createTitledBorder("BelowTop");
belowTopBorder.setTitlePosition(TitledBorder.BELOW_TOP);
JButton belowTopButton = new JButton();
belowTopButton.setBorder(belowTopBorder);
Container contentPane = frame.getContentPane();
contentPane.add(belowTopButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder.BOTTOM
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Double Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
topBorder.setTitlePosition(TitledBorder.TOP);
TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom",
TitledBorder.RIGHT, TitledBorder.BOTTOM);
JButton doubleButton = new JButton();
doubleButton.setBorder(doubleBorder);
Container contentPane = frame.getContentPane();
contentPane.add(doubleButton, BorderLayout.CENTER);
frame.setSize(300, 100);
frame.setVisible(true);
}
}
TitledBorder.CENTER
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Justified Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder centerBorder = BorderFactory.createTitledBorder("Center");
centerBorder.setTitleJustification(TitledBorder.CENTER);
JButton centerButton = new JButton();
centerButton.setBorder(centerBorder);
Container contentPane = frame.getContentPane();
contentPane.add(centerButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder.LEFT
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Justified Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder leftBorder = BorderFactory.createTitledBorder("Left");
leftBorder.setTitleJustification(TitledBorder.LEFT);
JButton leftButton = new JButton();
leftButton.setBorder(leftBorder);
Container contentPane = frame.getContentPane();
contentPane.add(leftButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder.RIGHT
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Double Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
topBorder.setTitlePosition(TitledBorder.TOP);
TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom",
TitledBorder.RIGHT, TitledBorder.BOTTOM);
JButton doubleButton = new JButton();
doubleButton.setBorder(doubleBorder);
Container contentPane = frame.getContentPane();
contentPane.add(doubleButton, BorderLayout.CENTER);
frame.setSize(300, 100);
frame.setVisible(true);
}
}
TitledBorder: setTitleJustification(int pos)
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Justified Titled Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder leftBorder = BorderFactory.createTitledBorder("Left");
leftBorder.setTitleJustification(TitledBorder.LEFT);
JButton leftButton = new JButton();
leftButton.setBorder(leftBorder);
Container contentPane = frame.getContentPane();
contentPane.add(leftButton);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
TitledBorder: setTitlePosition(int pos)
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Double Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
topBorder.setTitlePosition(TitledBorder.TOP);
TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom",
TitledBorder.RIGHT, TitledBorder.BOTTOM);
JButton doubleButton = new JButton();
doubleButton.setBorder(doubleBorder);
Container contentPane = frame.getContentPane();
contentPane.add(doubleButton, BorderLayout.CENTER);
frame.setSize(300, 100);
frame.setVisible(true);
}
}
TitledBorder.TOP
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Double Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
topBorder.setTitlePosition(TitledBorder.TOP);
TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom",
TitledBorder.RIGHT, TitledBorder.BOTTOM);
JButton doubleButton = new JButton();
doubleButton.setBorder(doubleBorder);
Container contentPane = frame.getContentPane();
contentPane.add(doubleButton, BorderLayout.CENTER);
frame.setSize(300, 100);
frame.setVisible(true);
}
}