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 7521337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:13:10+00:00 2026-05-30T02:13:10+00:00

I am creating custom Swing components and want to provide a UI that looks

  • 0

I am creating custom Swing components and want to provide a UI that looks just like Nimbus.

I know how to access the UIDefaults colors, but can I reuse more code, particularly, is there a way to get an object that paints the focus rings (rectangular or oval, or even better, along any outline Shape) exactly like the other Nimbus components do? (without reinventing the wheel)

  • 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-30T02:13:10+00:00Added an answer on May 30, 2026 at 2:13 am

    As I didn’t see any design decision in Nimbus to allow the reuse of painters for new components, and also I’m stuck on OS X with Java 6 and Nimbus being a moving (namespace) target, here is my solution which basically recreates what the Synth style is using:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.*;
    
    public class NimbusFocusBorder implements javax.swing.border.Border {
        private static final RoundRectangle2D rect = new RoundRectangle2D.Float();
        private static final Area area = new Area();
    
        private final float arcIn;
        private final float arcOut;
    
        public NimbusFocusBorder() {
            arcIn = arcOut = 0f;
        }
    
        public NimbusFocusBorder( float rounded ) {
            arcIn  = rounded * 2;
            arcOut = arcIn + 2.8f;
        }
    
        public void paintBorder( Component c, Graphics _g, int x, int y, int w, int h ) {
            if( !c.hasFocus() ) return;
            final Graphics2D g = (Graphics2D) _g;
            g.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON );
            g.setColor( /* NimbusHelper. */ getFocusColor() );
            rect.setRoundRect( x + 0.6, y + 0.6, w - 1.2, h - 1.2, arcOut, arcOut );
            area.reset();
            area.add( new Area( rect ));
            rect.setRoundRect( x + 2, y + 2, w - 4, h - 4, arcIn, arcIn );
            area.subtract( new Area( rect ));
            g.fill( area );
    
        }
    
        public Insets getBorderInsets( Component c ) {
            return new Insets( 2, 2, 2, 2 );
        }
    
        public boolean isBorderOpaque() { return false; }
    
        // this actually looks up the color in UIDefaults
        // in the real implementation
        private Color getFocusColor() { return new Color( 115, 164, 209, 255 );}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a tutorial that explains creating custom usercontrols in WPF. I want
I know of two ways of creating custom JSF components: 1. Native JSF way:
I just started with creating custom objects in javascript. I want to set this.someObjVar
I know that there are tons of links about creating custom configuration sections out
i'm reading the android developer docs on creating custom components and one thing that's
I need a help about creating custom wpf controls.I want to create a template
I need to implement creating custom gesture(like Gesture Builder in Android ) in my
I'm creating custom control that contain multiple parts. Inside template creation I'm subscribing for
Do you know any decent framework for creating Swing screens? I need to extend
I'm stuck with creating custom adapter. I want to setOnClickListener on the buttons inside

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.