TitleBorder Justification : TitiledBorder « Swing « Java Tutorial






TitleBorder Justification
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.TitledBorder;

public class TitledJustBorder {
  public static void main(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);
    
    TitledBorder rightBorder = BorderFactory.createTitledBorder("Right");
    rightBorder.setTitleJustification(TitledBorder.RIGHT);
    
    JButton rightButton = new JButton();
    rightButton.setBorder(rightBorder);
    
    TitledBorder centerBorder = BorderFactory.createTitledBorder("Center");
    centerBorder.setTitleJustification(TitledBorder.CENTER);
    
    JButton centerButton = new JButton();
    centerButton.setBorder(centerBorder);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(3, 1));
    contentPane.add(leftButton);
    contentPane.add(rightButton);
    contentPane.add(centerButton);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}








14.101.TitiledBorder
14.101.1.Creating TitledBorder through its constructors and helper method from BorderFactory
14.101.2.Nested TitiledBorderNested TitiledBorder
14.101.3.Setting TitiledBorder DirectionSetting TitiledBorder Direction
14.101.4.Set title position
14.101.5.TitleBorder Title PositionTitleBorder Title Position
14.101.6.TitledBorder based on LineBorderTitledBorder based on LineBorder
14.101.7.TitleBorder JustificationTitleBorder Justification
14.101.8.Create a title border from another border
14.101.9.Change border text Justification alignment style
14.101.10.Customizing TitledBorder Look and Feel