Draw only part of a shape transparent

Hi,
I have two shapes neither of which is transparent. However, the shapes overlap and I want the intersecting region on the foreground shape to be transparent so that we can see the background shape.
So how do I draw part of a shape transparently and the rest of it not transparent? If it is any help, I have a curve in front and a rectangle behind it. I want the curve to be semi-transparent whenever it covers the rectangle.
Maybe there is a much easier way to do this?

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class SeeThru extends JPanel {
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        int w = getWidth();
        int h = getHeight();
        g2.setPaint(Color.red);
        g2.fill(new Ellipse2D.Double(w/3, h/3, w/4, h/4));
        Rectangle2D r = new Rectangle2D.Double(w/4, h/4, w/4, h/4);
        Rectangle2D clip = new Rectangle2D.Double(w/4, h/4, w/4+1, h/4+1);
        g2.setClip(clip);
        g2.setPaint(getBackground());
        g2.fill(clip);
        g2.setPaint(Color.blue);
        g2.draw(r);
        int rule = AlphaComposite.SRC_OVER;
        float alpha = 0.25f;
        AlphaComposite ac = AlphaComposite.getInstance(rule, alpha);
        g2.setComposite(ac);
        g2.setPaint(Color.red);
        g2.fill(new Ellipse2D.Double(w/3, h/3, w/4, h/4));
    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new SeeThru());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • Ai, 3D effect - after using to either extrude or revolve the settings are retained in my drawing tools - pen, pencil and shapes. Example I draw a 50 pt extruded object in wireframe, isometric view and my pen and all drawing tools will only draw using thos

    Ai, 3D effect - after using to either extrude or revolve the settings are retained in my drawing tools - pen, pencil and shapes. Example I draw a 50 pt extruded object in wireframe, isometric view and my pen and all drawing tools will only draw using those settings. I can not exit, help please!

    Appearance panel menu > New art has basic appearance.

  • Drawing only a part of a JPanel

    Hello,
    Could someone tell me how I could only draw a part of my JPanel (for instance the part between x,y,width,height).
    Thanks,
    Joe

    How about panel.repaint(x,y,width,height)?

  • How to only keep overlapping parts of vector shapes

    I have a vector shape on top of a vector path drawing. The shape on top protrudes over the edge of the drawing underneath. Is there an easy way to simply remove the part of the shape that overhangs?
    In the screenshot here, I want to remove the part of the green circle that is not on the underlying green shape:

    Have you tried the Knife tool? Alternatively, you can draw a retangle over the area you want to remove, select both objects and then and choose Modify > Combine Paths > Punch.

  • How to make some part of front panel transparent?

    There is a property node to make a front panel completly transparent...but is there anything that only makes some part of the vi transparent like if I define a decorative block in the vi which takes 1 quardant of front panel and I have a control to make it transparent during runtime...
    And moreover the frontpanel transparent property makes the whole window transparent, is there any way to retain toolbar of window like stop, run button when front panel is transparent??

    Hi,
    Have a look at this VI (attached). To make it work you need to create an image mask as a .png (open paint, colour in the areas that you want to become invisible and save it as a .png). The VI diffentiates between white areas and black areas of the mask you create, the black areas will become transparent and the white areas will remain the same- this will be implemented on your front panel. I've included an example of a possible paint image in "mask2.png".
    You may also want to play around with the resolution of the mask created in paint, this will effect how the program works (I advise you use a lower resolution than your display- I used 500x300)
    NT: If the front panel controls disappear, go into the block diagram window and attach a false constant instead of a control. Let me know if this works
    Cheers, Tom
    Attachments:
    custom window.zip ‏107 KB

  • How to make a stroke part of the shape

    One of the letters (S) on a logo I am working on doesn't look the right thickness alongside the other letters - there isnt a bolder version available so I have added a small stroke to make it visually balanced (text is converted to outlines). I would now like to make that stroke part of the shape (ie no separate stroke, but thickness of the letter with the stroke). I'm sure I've come across how to do this before, but cant seem to find it now... can you help? Many thanks.

    Caroline,
    how is that different to just adding a stroke the normal way?
    It is only in the sense that it may be done with a single letter in Live Type, thus enabling individual changes of appearance of letters and still allowing your editing everything (the/each special letter must be selected by itself, and then you can type in one or more replacement letters with the same appearance).
    I just thought I should mention it, in case it might be preferable.

  • Stroking only part of a compound path

    Hi,
    I am working on a file where there are kangaroos that are compound paths. I need to stroke only parts of them. Is there a way to do that? Should I just manually be drawing paths that go right up to the edge of the compund path (drawing my own stroke)?
    Thanks!

    The kangaroos need to be stroked only on the parts where they hit the blue background for a phenomenon called "trapping" in photolithography printing.

  • "Only Part I" for Goods receipt (MIGO) in excise invoice tab

    Dear Gurus,
    I have configured a material with all CIN configuration setting, while doing goods receipt for that material I want to capture excise invoice through excise invoice tab, for which i need to select " Only Part 1" in the invoice tab.
    But in my currrent senario while posting goods recipt, In excise invoice tab, I am not detting " Only part 1" option when i select excise invoice tab.
    How to configure "only part 1" option to appear in  excise invoice tab.
    Kindly help...
    Regards,
    Prashanth Pai

    Hi,
    Check in
    Tax on Goods Movements - India - Business Transactions - Incoming Excise Invoices -  Specify Which Movement Types Involve Excise Invoices -
    ensure that RG23A & RG23 C Register is maintained against the movement types you are using.
    Regards,
    Vikas

  • How to draw only straight line instead of angled one??

    Dear friends,
    I saw a very good code posted by guru here(I think is camickr),
    But I tried to change it and I hope to draw only straight line instead of angled one, can you help how to do it??
    Thanks so much.
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DrawingArea extends JPanel
         Vector angledLines;
         Point startPoint = null;
         Point endPoint = null;
         Graphics g;
         public DrawingArea()
              angledLines = new Vector();
              setPreferredSize(new Dimension(500,500));
              MyMouseListener ml = new MyMouseListener();
              addMouseListener(ml);
              addMouseMotionListener(ml);
              setBackground(Color.white);
         public void paintComponent(Graphics g)
              // automatically called when repaint
              super.paintComponent(g);
              g.setColor(Color.black);
              AngledLine line;
              if (startPoint != null && endPoint != null)
                   // draw the current dragged line
                   g.drawLine(startPoint.x, startPoint.y, endPoint.x,endPoint.y);
              for (Enumeration e = angledLines.elements(); e.hasMoreElements();)
                   // draw all the angled lines
                   line = (AngledLine)e.nextElement();
                   g.drawPolyline(line.xPoints, line.yPoints, line.n);
         class MyMouseListener extends MouseInputAdapter
              public void mousePressed(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        startPoint = e.getPoint();
              public void mouseReleased(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        if (startPoint != null)
                             AngledLine line = new AngledLine(startPoint, e.getPoint(), true);
                             angledLines.add(line);
                             startPoint = null;
                             repaint();
              public void mouseDragged(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        if (startPoint != null)
                             endPoint = e.getPoint();
                             repaint();
              public void mouseClicked( MouseEvent e )
                   if (g == null)
                        g = getGraphics();
                   g.drawRect(10,10,20,20);
         class AngledLine
              // inner class for angled lines
              public int[] xPoints, yPoints;
              public int n = 3;
              public AngledLine(Point startPoint, Point endPoint, boolean left)
                   xPoints = new int[n];
                   yPoints = new int[n];
                   xPoints[0] = startPoint.x;
                   xPoints[2] = endPoint.x;
                   yPoints[0] = startPoint.y;
                   yPoints[2] = endPoint.y;
                   if (left)
                        xPoints[1] = startPoint.x;
                        yPoints[1] = endPoint.y;
                   else
                        xPoints[1] = endPoint.x;
                        yPoints[1] = startPoint.y;
         public static void main(String[] args)
              JFrame frame = new JFrame("Test angled lines");
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              DrawingArea d = new DrawingArea();
              frame.getContentPane().add( d );
              frame.pack();
              frame.setVisible(true);
    }

    Change the AngledLine class to store two points instead of 3 points (I would rename the class to be StraightLine). The code is much simpler because you just store the starting and ending points and you don't need to calculate the middle point.

  • I use Windows Vista and Microsoft Outlook. After migrating to iCloud, the calendar of iCloud tranferred only part of my past Calendar items to the folder iCloud Calendar in my Outlook. How can I transfer all the entries?

    I use Windows Vista and Microsoft Outlook. After migrating to iCloud, the calendar of iCloud tranferred only part of my past Calendar items to the folder iCloud Calendar in my Outlook. How can I transfer all the entries? In iCloud's site all are there.

    If the calendar is on iCoud.com, all you would need to do to get it on your phone is go to Settings>iCloud on your phone, sign into your iCoud account and turn Calendars on.  The iCloud calendars will then download to your phone.

  • I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page word document, some recipients get only one page.  Also sometimes when I burn an image from iPhoto on to a disc, only part of the image appears.  Why?

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

  • I downloaded audiobook from iTunes. It comes in 2 parts. Part one will not play, only part 2. When I tried to sync to ipod or iphone it prompted,"file could not be reaf from or written to".Can I fix this issue?

    I just purchased and downloaded an audiobook from iTunes. I tried to sync it to iPhone 4 and iPod Classic but with both devices got a message"file could not be read from to written to".  Then I tried to play the audiobook in iTunes and realized that only part 2 of my 2 part download will play. Part 1 will not play. Is this why I got the message? Is there any way to get another try at downloading my audiobook I just paid $15 for??

    Click the Shuffle button at bottom left of iTunes window so the crossed arrows are not blue.

  • Excise Goods Receipt Without  Only Part I

    Hi,
    We have done a goods receipt for an excisable material.
    At the time of goods receipt, we could not select "Only Part I"
    Now we want to post the Vendor Excise Invoice,
    I just ran the T Code J1I5 with Classification ROP and I am able to update the RG Part I Register,
    Now I want to post the excise value using T Code J1IH. Here I am confused which button to select . Here we get options like Additional excise, Other adjustment.
    Request you to please guide.
    What is the best way to handle this type of situation.
    Regards,

    Hi PK,
             The amount what u are seeing in the top is the cumulative amount for that month. What u have to do before doing the MMPV that select the value based on the account for e.g RG23BED then select the line and press the create menu button in the tool bar and then it ask in which account need to post it (i.e) at the bottom account. u have to select the top and bottom are the same one then if u save it once the system take entire amount in the top and deduct the same from the bottom account.
    That means the amount in the register will get reduce. The amount what ever u did the utilisation that will go and sit in the PLA account. From the PLA account the amount will be disbursed to the excise department. If u have not done then your PLA account will be more that means u have to pay more to your excise department without set-off amount.Loss to company.
    a. we are in back-log mode right now, if we don't run J2IUN, what will happen?. Is this statutory? Or will it impact our financial?
    Not a problem all back -log can be utilised at one shot and if u not run the J2IUn your set-off amount cannot be get back from excise.It is statutory.Yes it will impact your financial means your paying the both input and out put tax to the excise.
    b. what if I run J2IUN after we complete all the backlogs or year end?
    You have to do as a monthly basis not a year basis.Last financial year back log cannot be utllised for this year.
    c. What query should I put across to our client to know about their existing process?
    Whether they have a set-off process (Earlier they used to call Modvet) or all input taxes are inventories. Only this transaction is right for all the set-off invoices.i am sure all the OEM will have the set-off requirement
    d What query should I put across to our FI Consultant regarding this T Code.
    Ask him whether he checked all the GL balance for all these registers for ex RG23ABED get Zero. whether he is checking the PLA account. The output tax and input tax is properly got off-set.All the Excise GL Need to be reconcile at the month end. This is very very important activities.
    e. Is this the job of MM User or FI User (so that I can accordingly impart the KT)
    Utilisation is MM activity but FI consultant need to be with u because the posting date what ever u are giving in the input selection screen for the J2iUN that he has to tell . What ever date u give them system will post the accounting doc for that period. so be carfrul.
    Thanks
    Ganesh

  • Moving only part of iphoto library to external hard drive

    I would like to only move part of my iphoto library to an external hard drive.  Trying to archive my older pictures.  I know how to move the entire library but not so sure on how to move only parts of the library.  Do i need to create a second archived library and move the pictures I want to archive to that archived libary and then move the archived libary to an external hard drive?

    Here's one way to do it:
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    Now you have two full versions of the Library.
    3. On the Internal library, trash the Events you don't want there
    Now you have a full copy of the Library on the External and a smaller subset on the Internal
    Some Notes:
    As a general rule: when deleting photos do them in batches of about 100 at a time. iPhoto can baulk at trashing large numbers at one go.
    You can choose which Library to open: Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Choose Library'
    You can keep the Library on the external updated with new imports using iPhoto Library Manager

  • With 2 devices, how do I sync only part of the library on one device? That is, sync only music and not the podcasts.

    Trying to sync part of a library on one device and all of the library on another. Not finding any options to select only parts of a library to be sync'ed. Any help appreciated.

    In ipod menu in iTunes, tick the "manually manage music and videos" then select the items that you want to sync. Cheers!

Maybe you are looking for

  • Not Able to view layuot in SFP despite Adobe Life Cycle Designer on system

    Hi Friends ,     I have installed Adobe Life Cycle Designer 8.0 on my system and I am running SAP version 7.10 with patch level 8.Is there any other setting to be done because I am still getting same error when I try to view layout in SFP . Please he

  • Apple Mail search not working for Inbox

    In the last few weeks I've notice the Apple Mail (5.2) search feature has stopped working correctly.  It used to turn up all relevant results in a mail box, then lately it seems (based on the results) to go back just a few weeks and not the full year

  • 3gs wont start up/ only white screen.

    Whats happened, is I had updated my 3gs from ios 6.0 to 6.0.1without any problems, as i have done many other times. (upgrading from previous ios's from 3xx upto now etc) anyway about 30mins later i noticed it just turned off while it was still connec

  • Sound is very quiet !

    Hi I recently bought a zen mp3 from 32 GB but now I've put some songs on it and the sound is very quiet, even when I put it on 25 ! my brother has a zen mp3 of 8 GB and his sound is very loud at 25. Does anyone knows how i can get the songs to play l

  • Cross-site scripting vulnerability RoboHelp 10 version

    Has the cross-site scripting vulnerability been addressed in the RoboHelp 10 version