Change TitledBorder Direction in Java
Description
The following code shows how to change TitiledBorder Direction.
Example
/*ww w. java 2 s . c o m*/
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 Main {
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);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »