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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:55:46+00:00 2026-05-23T01:55:46+00:00

How do you define a clipping region (via Graphics2D.clip(Shape) ) that has a hole

  • 0

How do you define a clipping region (via Graphics2D.clip(Shape)) that has a hole in it?

for example: a Rectangle r1 minus another Rectangle r2 inside r1

I’m sure this has an easy answer, but I’m drawing a blank.

  • 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-23T01:55:47+00:00Added an answer on May 23, 2026 at 1:55 am

    Path2D.append() + EVEN_ODD winding rule appear to do the trick:

    enter image description here

    package com.example.test.gui;
    
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Line2D;
    import java.awt.geom.Path2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class HoleClipper extends JPanel
    {
        @Override protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;
            Rectangle2D r1 = getBounds();
            int margin = 50;
            Rectangle2D r2 = new Rectangle2D.Double(
                    r1.getMinX()+margin,
                    r1.getMinY()+margin,
                    r1.getWidth()-2*margin,
                    r1.getHeight()-2*margin);
    
            g2d.setColor(Color.YELLOW);
            g2d.fill(r1);
    
            Path2D p = new Path2D.Double(Path2D.WIND_EVEN_ODD);
            p.append(r1, false);
            p.append(r2, false);
            g2d.clip(p);
    
            int spacing = 10;
            g2d.setColor(Color.BLACK);
            for (double d = 0; d < r1.getWidth() + r1.getHeight(); d += spacing)
            {
                Line2D line = new Line2D.Double(0, d, d, 0);
                g2d.draw(line);
            }
        }
    
        public static void main(String[] args) {
            HoleClipper clipper = new HoleClipper();
            clipper.setPreferredSize(new Dimension(300, 200));
    
            JFrame frame = new JFrame("HoleClipper");
            frame.setContentPane(clipper);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Define a function called symcount that takes a symbol and a list and returns
Define a list: nat2::[(Integer, Integer)] that contains all pairs of nonnegative integers ordered by
I have a form that has a field that needs to be rendered as
define('key_start_atz', 200); $str = 'key_start_atz'; How can I get 200 via $str ?
Define a procedure, same_structure, that takes two inputs. It should output True if the
// Define a walk_the_DOM function that visits every // node of the tree in
#define BUF_SIZE 10 char *html = foo:baa\r\nxxx:yyyy:\r\nLocation:........................................\r\Connection:close\r\n\r\n; char *p = (char*)html, *buf, *pbuf, *tbuf;
(define (lcs lst1 lst2) (define (except-last-pair list) (if (pair? (cdr list)) (cons (car list)
#define MAX 100 struct bs{ int ab; int ac; }be; struct s{ be b;
#define HISTORY_SIZE 50 #define INPUT_SIZE 512 /*Max input size*/ char input[INPUT_SIZE]; /*Holding user input

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.