Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:47:13+00:00 2026-05-31T13:47:13+00:00

i used class to make rounded border the class is : public class RoundedBorder

  • 0

i used class to make rounded border

the class is :

public class RoundedBorder implements Border {
        int radius;

        public RoundedBorder(int radius) {
            this.radius = radius;
        }
    @Override
        public Insets getBorderInsets(Component c) {
            return new Insets(this.radius/2, this.radius, this.radius/2, this.radius);
        }
    @Override
        public boolean isBorderOpaque() {
            return true;
        }
    @Override
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            Graphics2D graphics = (Graphics2D) g;
            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            g.drawRoundRect(x,y,width-1,height-1,radius,radius);           
        }
    }

and for button i used :

JTextField login_nickname = new JTextField();

login_nickname.setBorder(new RoundedBorder(10));
login_nickname.setPreferredSize(new Dimension(150, 25));

and it’s worked fine , but i want remove unused background outside rounded border in corner , i attached image to explain more what i mean,

enter image description here

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:47:14+00:00Added an answer on May 31, 2026 at 1:47 pm

    I would do something like this in paintBorder():

    @Override
     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
         Graphics2D graphics = (Graphics2D) g;
         graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         if (c.getParent() != null) {
             Color bc = g.getColor();
             g.setColor(c.getParent().getBackground());
             for (int r = 0; r<radius;r++){
                g.drawRoundRect(x, y, width - 1, height - 1, r, r);
             }
             g.setColor(bc);
         }
         g.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
     }
    

    If the component has some parent container, i would draw first the border with the background color, then on top of it – my round border.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this class used for DB mapping. [Bind()] public class ActiveType { [Key()] public
I have used Bitmap class to convert tiff to Gif but it couldn't make
Wiki said it used to make class,interface uniquely identifier , how about object (actual
For previous projects I have used /** * HTTP Class * * This is
What can I do to make this work: template<class C, class V, Test V::*>
I have never used DBIx::Class until today, so I'm completely new at it. I'm
Thus for used base class for some commom reusable methods in every page of
I'm trying to implement onTouch in my class used to remote control a mindstorms
In Java, what is the Scanner class used for?
The following class is used by another program. When it is accessed, it throws

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.