Oval border : Border « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing JFC » BorderScreenshots 
Oval border
Oval border


import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class OvalBorder implements Border {
  protected int ovalWidth = 6;

  protected int ovalHeight = 6;

  protected Color lightColor = Color.white;

  protected Color darkColor = Color.gray;

  public OvalBorder() {
    ovalWidth = 6;
    ovalHeight = 6;
  }

  public OvalBorder(int w, int h) {
    ovalWidth = w;
    ovalHeight = h;
  }

  public OvalBorder(int w, int h, Color topColor, Color bottomColor) {
    ovalWidth = w;
    ovalHeight = h;
    lightColor = topColor;
    darkColor = bottomColor;
  }

  public Insets getBorderInsets(Component c) {
    return new Insets(ovalHeight, ovalWidth, ovalHeight, ovalWidth);
  }

  public boolean isBorderOpaque() {
    return true;
  }

  public void paintBorder(Component c, Graphics g, int x, int y, int width,
      int height) {
    width--;
    height--;

    g.setColor(lightColor);
    g.drawLine(x, y + height - ovalHeight, x, y + ovalHeight);
    g.drawArc(x, y, * ovalWidth, * ovalHeight, 180, -90);
    g.drawLine(x + ovalWidth, y, x + width - ovalWidth, y);
    g.drawArc(x + width - * ovalWidth, y, * ovalWidth, * ovalHeight,
        90, -90);

    g.setColor(darkColor);
    g.drawLine(x + width, y + ovalHeight, x + width, y + height
        - ovalHeight);
    g.drawArc(x + width - * ovalWidth, y + height - * ovalHeight,
        * ovalWidth, * ovalHeight, 0, -90);
    g
        .drawLine(x + ovalWidth, y + height, x + width - ovalWidth, y
            + height);
    g.drawArc(x, y + height - * ovalHeight, * ovalWidth,
        * ovalHeight, -90, -90);
  }

  public static void main(String[] s) {
    JFrame f = new JFrame("Oval Border");
    f.setSize(100100);

    JPanel p = new JPanel(new GridLayout(0155));
    JLabel l = new JLabel("Oval Border");

    l.setBorder(new OvalBorder());

    p.add(l);
    p.setBorder(new OvalBorder());

    f.getContentPane().add(p);
    f.show();
  }
}
           
       
Related examples in the same category
1. Border Demo Border Demo
2. Different Swing bordersDifferent Swing borders
3. demonstrate the custom CurvedBorder classdemonstrate the custom CurvedBorder class
4. An example of the MatteBorder classAn example of the MatteBorder class
5. A simple demontstration of the LineBorder class built with rounded cornersA simple demontstration of the LineBorder class built with rounded corners
6. An example of using a titled border on a labelAn example of using a titled border on a label
7. Borders with a BevelBorder used on JLabels as a highlightBorders with a BevelBorder used on JLabels as a highlight
8. MatteBorder DemoMatteBorder Demo
9. TitledBorder DemoTitledBorder Demo
10. Custom Border SampleCustom Border Sample
11. How to create the borderHow to create the border
12. Solid border button border 3D borderSolid border button border 3D border
13. Border of all kindsBorder of all kinds
14. EtchedBorderEtchedBorder
15. Red Green BorderRed Green Border
16. TitledBorderTitledBorder
17. TitledBorder 3TitledBorder 3
18. BevelBorder 2BevelBorder 2
19. Icon MatteBorderIcon MatteBorder
20. Soft BevelBorderSoft BevelBorder
21. Another TitledBorder 1Another TitledBorder 1
22. BevelBorderBevelBorder
23. EmptyBorderEmptyBorder
24. LineBorder DemoLineBorder Demo
25. CompoundBorder DemoCompoundBorder Demo
w___w_w__._j___a__v_a_2_s.__c__om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.