Setting TitiledBorder Direction : TitiledBorder « Swing « Java Tutorial






Setting TitiledBorder Direction
import java.awt.Color;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

public class ChangingTitleBorderDirection {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Border lineBorder = new LineBorder(Color.RED, 5);
    
    Font font = new Font("Serif", Font.ITALIC, 12);
    Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT,
        TitledBorder.BELOW_BOTTOM, font, Color.RED);

    
    JLabel aLabel = new JLabel("Bevel");
    aLabel.setBorder(titledBorder);
    aLabel.setHorizontalAlignment(JLabel.CENTER);

    frame.add(aLabel);
    frame.setSize(400, 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