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

  • Home
  • SEARCH
  • 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 8565489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:26:18+00:00 2026-06-11T17:26:18+00:00

I need to have a rounded corner text field and I found the solution

  • 0

I need to have a rounded corner text field and I found the solution here the problem is that with this solution I lose all the standard JTextField shadows.

Does anyone know how to restore them?

  • 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-06-11T17:26:20+00:00Added an answer on June 11, 2026 at 5:26 pm

    You cannot simply replace original textfield border without losing the shadow. You will have to apply some specific border with your own shadow-like effect or even modify the UI so it paints the shadow around the field.

    Here is a simple example of shadow-like UI for textfield:

    public static class RoundedFieldUI extends BasicTextFieldUI
    {
        private int round = 5;
        private int shadeWidth = 2;
        private int textSpacing = 3;
    
        public void installUI ( JComponent c )
        {
            super.installUI ( c );
    
            c.setOpaque ( false );
    
            int s = shadeWidth + 1 + textSpacing;
            c.setBorder ( BorderFactory.createEmptyBorder ( s, s, s, s ) );
        }
    
        protected void paintSafely ( Graphics g )
        {
            Graphics2D g2d = ( Graphics2D ) g;
            g2d.setRenderingHint ( RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON );
    
            Shape border = getBorderShape ();
    
            Stroke os = g2d.getStroke ();
            g2d.setStroke ( new BasicStroke ( shadeWidth * 2 ) );
            g2d.setPaint ( Color.LIGHT_GRAY );
            g2d.draw ( border );
            g2d.setStroke ( os );
    
            g2d.setPaint ( Color.WHITE );
            g2d.fill ( border );
    
            g2d.setPaint ( Color.BLACK );
            g2d.draw ( border );
    
            super.paintSafely ( g );
        }
    
        private Shape getBorderShape ()
        {
            JTextComponent component = getComponent ();
            if ( round > 0 )
            {
                return new RoundRectangle2D.Double ( shadeWidth, shadeWidth,
                        component.getWidth () - shadeWidth * 2 - 1,
                        component.getHeight () - shadeWidth * 2 - 1, round * 2, round * 2 );
            }
            else
            {
                return new Rectangle2D.Double ( shadeWidth, shadeWidth,
                        component.getWidth () - shadeWidth * 2 - 1,
                        component.getHeight () - shadeWidth * 2 - 1 );
            }
        }
    
        public static void main ( String[] args )
        {
            JFrame frame = new JFrame ();
    
            JPanel panel = new JPanel ( new BorderLayout ( 5, 5 ) );
            panel.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) );
            frame.add ( panel );
    
            panel.add ( new JLabel ( "Field:" ), BorderLayout.NORTH );
    
            JTextField field = new JTextField ( 20 );
            field.setUI ( new RoundedFieldUI () );
            panel.add ( field );
    
            frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
            frame.pack ();
            frame.setLocationRelativeTo ( null );
            frame.setVisible ( true );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are creating an XBAP application that we need to have rounded corners in
I have this problem; I'm currently doing some modification on a web application that
I have an image with rounded corners. I need to stretch the image without
I have need to pack four signed bytes into 32-bit integral type. this is
I have need for a function pointer that takes two arguments and returns a
I need to have custom checkboxes which wasn't that tricky. I made checkbox_selector to
OK, I have my site going pretty well here: http://www.marioplanet.com But I've realized that
I need rounded corner with background image for or on IE6 and above I
In my app i have a list view, in that i need to place
I have NSTextView and need rounded corners for the same. Hence i tried using

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.