Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Yazar: Serdar KUZUCU
- * http://blog.asosyalbebe.com/
- */
- package sedran.borders;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.geom.Rectangle2D;
- import javax.swing.border.Border;
- public class TextBorder implements Border {
- private String title = "";
- private Font f = new Font("Tahoma", Font.PLAIN, 11);
- private Insets insets = new Insets(23, 9, 9, 9);
- private Color line_color = new Color(148,145,140);
- private Color text_color = new Color(20,20,20);
- private boolean rounded = false;
- public TextBorder(String title) {
- this.title = title;
- }
- public void setText(String text) {
- this.title = text;
- }
- public void setBorderColor(Color c) {
- line_color = c;
- }
- public void setTextColor(Color c) {
- text_color = c;
- }
- public void setRounded(boolean round) {
- rounded = round;
- }
- public void setFont(Font f) {
- this.f = f;
- }
- public Font getFont() {
- return this.f;
- }
- public String getText() {
- return title;
- }
- public Insets getBorderInsets(Component c) {
- return new Insets(insets.top, insets.left, insets.bottom, insets.right);
- }
- public boolean isBorderOpaque() {
- return true;
- }
- public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
- int roundWidth = rounded ? 15 : 0;
- g.setColor(line_color);
- g.drawRoundRect(x+3, y+10, width-6, height-13, roundWidth, roundWidth);
- g.setColor(Color.WHITE);
- g.drawRoundRect(x+4, y+11, width-8, height-15, roundWidth, roundWidth);
- g.setFont(f);
- FontMetrics fm = g.getFontMetrics(f);
- Rectangle2D textsize = fm.getStringBounds(title, g);
- g.setColor(c.getBackground());
- g.fillRect(x+12, y+9, (int)textsize.getWidth()+6, 4);
- g.setColor(text_color);
- g.drawString(title, x+15, y+fm.getAscent()+3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement