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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:49:54+00:00 2026-05-12T09:49:54+00:00

I want to fill a region using Graphics.fillRoundRect(), but I want a rectangle in

  • 0

I want to fill a region using Graphics.fillRoundRect(), but I want a rectangle in the middle of it to not be filled.

Essentially, given a component of 100×30, I want to set clipping to be the rectangle at 10,10 of size 80×10 but have the fill only paint the area outside that 80×10 rectangle. The reason is that I want a border of n pixels with a curved outline painted without affecting the inside component area.

The best way I can see so far is to clip to 10,10 90×10 and do the fillRoundRect() and then clip to 90,10 10×10 and do a fillRect() to fill in the right hand side, below and above the corners.

If I simple repaint a single line rectangle then I end up with “spotting” on the corners because the curves don’t quite abut (and/or because AA affects surrounding pixels).

EDIT: Caveat – I need a way to do it which will work with J2ME AWT (CDC with Personal Profile 1.1) as well as J2SE.


Edit: Another similar question has an an answer I was able to adapt. The code that works correctly for my situation is posted as a self-answer.

  • 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-12T09:49:54+00:00Added an answer on May 12, 2026 at 9:49 am

    I have a similar answer on the other question too, which is to use a polygon as an AWT clip. Maybe this is supported in J2ME? You’ll need to know the bounds of the rectangle you want to exclude, and the outer bounds of your drawing area.

    +-------------------+
    | clip drawing area |
    +---+-----------+   |
    |   | excluded  |   |
    |   |   area    |   |
    |   +-----------+   |
    |                   |
    +-------------------+
    

    EDIT FROM OP.

    This answer worked for me and the API’s are supported on J2ME. The answer of the other question appears to have one mistake – the set of coordinates needs to start a the point on the outer-left and inner top in order to create an enclosed polygon. My final code which worked follows:

    To create a clipping Shape, I used this method:

    static public Shape getOutsideEdge(Graphics gc, Rectangle bb, int top, int lft, int btm, int rgt) {
        int                                 ot=bb.y            , it=(ot+top);
        int                                 ol=bb.x            , il=(ol+lft);
        int                                 ob=(bb.y+bb.height), ib=(ob-btm);
        int                                 or=(bb.x+bb.width ), ir=(or-rgt);
    
        return new Polygon(
         new int[]{ ol, ol, or, or, ol, ol,   il, ir, ir, il, il },
         new int[]{ it, ot, ot, ob, ob, it,   it, it, ib, ib, it },
         11
         );
        }
    

    which I set into the Graphics context and then filled my rectangle:

    Rectangle tmp=new Rectangle(px,py,pw,ph);
    gc.setClip(getOutsideEdge(gc,tmp,thickness,thickness,thickness,thickness));
    gc.fillRoundRect(px,py,pw,ph,RADIUS,RADIUS);
    

    and then I created the illusion of rounded inside corners by painting a single dot in each corner:

    gc.setClip(px,py,pw,ph);
    gc.drawLine((px   +thickness  ),(py   +thickness  ),(px   +thickness  ),(py   +thickness  ));
    gc.drawLine((px+pw-thickness-1),(py   +thickness  ),(px+pw-thickness-1),(py   +thickness  ));
    gc.drawLine((px   +thickness  ),(py+ph-thickness-1),(px   +thickness  ),(py+ph-thickness-1));
    gc.drawLine((px+pw-thickness-1),(py+ph-thickness-1),(px+pw-thickness-1),(py+ph-thickness-1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using matlab's FILL function creates a filled region confined by a polygon with straight
I want to fill a DataGridView control using DataAdapter. But I don't know how
I want to fill a table with a list of results. But not sure
I'd like to do something like fill-region, except that I want to select a
here's my question, i want to fill the content div with white. BUT when
I want to fill in recipient and sender fields on this website http://sms.orange.pl/ using
The issue I am having is that I want to fill an oval, but
I want fill five years in a drop-down using javascript and the years will
I want to fill a polygon shape that I have drawn via Core Graphics
I want to fill a bean list property using Spring properties place holder. Context

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.