BorderChooser() {
Border blackline, etched, raisedbevel, loweredbevel, empty;
//A border that puts 10 extra pixels at the sides and
//bottom of each pane.
Border paneEdge = BorderFactory.createEmptyBorder(0,10,10,10);
blackline = BorderFactory.createLineBorder(Color.black);
etched = BorderFactory.createEtchedBorder();
raisedbevel = BorderFactory.createRaisedBevelBorder();
loweredbevel = BorderFactory.createLoweredBevelBorder();
empty = BorderFactory.createEmptyBorder();
/* ------------------ First pane: simple borders ------------------ */
JPanel simpleBorders = new JPanel();
simpleBorders.setBorder(paneEdge);
simpleBorders.setLayout(new BoxLayout(simpleBorders,
BoxLayout.Y_AXIS));
addCompForBorder(empty, "Empty",
simpleBorders);
addCompForBorder(blackline, "Line",
simpleBorders);
addCompForBorder(etched, "Etched",
simpleBorders);
addCompForBorder(raisedbevel, "Raised Bevel",
simpleBorders);
addCompForBorder(loweredbevel, "Lowered Bevel",
simpleBorders);
/* ------------------ Second pane: matte borders ------------------ */
JPanel matteBorders = new JPanel();
matteBorders.setBorder(paneEdge);
matteBorders.setLayout(new BoxLayout(matteBorders,
BoxLayout.Y_AXIS));
//XXX: We *should* size the component so that the icons tile OK.
//XXX: Without that, the icons are likely to be cut off and look bad.
ImageIcon icon = new ImageIcon("images/left.gif"); //20x22
Border border = BorderFactory.createMatteBorder(-1, -1, -1, -1, icon);
addCompForBorder(border,
"matte border (-1,-1,-1,-1,icon)",
matteBorders);
border = BorderFactory.createMatteBorder(1, 5, 1, 1, Color.red);
addCompForBorder(border,
"matte border (1,5,1,1,Color.red)",
matteBorders);
border = BorderFactory.createMatteBorder(0, 20, 0, 0, icon);
addCompForBorder(border,
"matte border (0,20,0,0,icon)",
matteBorders);
/* ------------------ Third pane: titled borders ------------------ */
this.titledBorders = new JPanel();
this.titledBordersList = new Vector();
this.titledBorders.setBorder(paneEdge);
this.titledBorders.setLayout(new BoxLayout(this.titledBorders,
BoxLayout.Y_AXIS));
this.titledBorders.add(Box.createRigidArea(new Dimension(0, 10)));
JPanel titleFieldPanel = new JPanel();
titleFieldPanel.add(new JLabel("Title : "));
JTextField titlefield = new JTextField(20);
titlefield.addActionListener(new ActionListener() {
public final void actionPerformed(ActionEvent evt) {
String title = ((JTextField) evt.getSource()).getText();
int count = BorderChooser.this.titledBordersList.size();
for (int i = 0; i < count; i++) {
Object comp = BorderChooser.this.titledBordersList.get(i);
if (comp instanceof TitledBorder) {
((TitledBorder) comp).setTitle(title);
}
}
BorderChooser.this.titledBorders.repaint();
}
});
titleFieldPanel.add(titlefield);
this.titledBorders.add(titleFieldPanel);
TitledBorder titled;
titled = BorderFactory.createTitledBorder("title");
this.titledBordersList.add(titled);
addCompForBorder(titled,
"default titled border"
+ " (default just., default pos.)",
this.titledBorders);
titled = BorderFactory.createTitledBorder(blackline, "title");
this.titledBordersList.add(titled);
addCompForTitledBorder(titled,
"titled line border"
+ " (centered, default pos.)",
TitledBorder.CENTER,
TitledBorder.DEFAULT_POSITION,
this.titledBorders);
titled = BorderFactory.createTitledBorder(etched, "title");
this.titledBordersList.add(titled);
addCompForTitledBorder(titled,
"titled etched border"
+ " (right just., default pos.)",
TitledBorder.RIGHT,
TitledBorder.DEFAULT_POSITION,
this.titledBorders);
titled = BorderFactory.createTitledBorder(loweredbevel, "title");
this.titledBordersList.add(titled);
addCompForTitledBorder(titled,
"titled lowered bevel border"
+ " (default just., above top)",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.ABOVE_TOP,
this.titledBorders);
titled = BorderFactory.createTitledBorder(empty, "title");
this.titledBordersList.add(titled);
addCompForTitledBorder(titled, "titled empty border"
+ " (default just., bottom)",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.BOTTOM,
this.titledBorders);
/* ---------------- Fourth pane: compound borders ----------------- */
JPanel compoundBorders = new JPanel();
compoundBorders.setBorder(paneEdge);
compoundBorders.setLayout(new BoxLayout(compoundBorders,
BoxLayout.Y_AXIS));
Border redline = BorderFactory.createLineBorder(Color.red);
Border compound;
compound = BorderFactory.createCompoundBorder(
raisedbevel, loweredbevel);
addCompForBorder(compound, "compound border (two bevels)",
compoundBorders);
compound = BorderFactory.createCompoundBorder(
redline, compound);
addCompForBorder(compound, "compound border (add a red outline)",
compoundBorders);
titled = BorderFactory.createTitledBorder(
compound, "title",
TitledBorder.CENTER,
TitledBorder.BELOW_BOTTOM);
addCompForBorder(titled,
"titled compound border"
+ " (centered, below bottom)",
compoundBorders);
addTab("Simple", null, simpleBorders, null);
// addTab("Matte", null, matteBorders, null);
addTab("Titled", null, this.titledBorders, null);
addTab("Compound", null, compoundBorders, null);
setSelectedIndex(0);
}