new TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor) : TitledBorder « javax.swing.border « Java by API






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);
  }
}

           
       








Related examples in the same category

1.TitledBorder.ABOVE_BOTTOM
2.TitledBorder.ABOVE_TOP
3.TitledBorder.BELOW_BOTTOM
4.TitledBorder.BELOW_TOP
5.TitledBorder.BOTTOM
6.TitledBorder.CENTER
7.TitledBorder.LEFT
8.TitledBorder.RIGHT
9.TitledBorder.TOP
10.new TitledBorder(Border border, String title)
11.new TitledBorder(Border border, String title, int titleJustification, int titlePosition)
12.TitledBorder: setTitleJustification(int pos)
13.TitledBorder: setTitlePosition(int pos)