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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:51:13+00:00 2026-06-03T11:51:13+00:00

I’m not sure if this is possible, but is there a way to safely

  • 0

I’m not sure if this is possible, but is there a way to safely allow popups to be translucent even when the parent container is also translucent?

If not, what would be wise alternative to use or extend instead of JPopupMenu?

Note: Translucent refers to a component not ‘having a background’, similar to the effect of setOpaque(false);. Thanks.

From a forum answer by user camickr in 2009:

I don’t know if transparency painting has changed in 1.6.0_10. Prior
to that I believe transparency can only be achieved in lightweight
components (ie. Swing does all the painting). JFrame, JWindow and
JDialog are not lightweight because they use OS components.

In the case of a popup, it is lightweight when entirely contained
within its parent frame. But a lightweight popup can not be painted
outside the bounds of the frame so a JWindow (I believe) is used as
the popup, which can’t be transparent.

SSCCE: Showing translucent JWindow over the top of translucent JFrame

import com.sun.awt.AWTUtilities;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class OpaqueWindowSSCCE {

    private int countdown = 5;

    public static void main(String[] args) {
        new OpaqueWindowSSCCE();
    }

    public OpaqueWindowSSCCE() {
        final JFrame frame = new JFrame("OpaqueWindowSSCCE");
        final JWindow window = new JWindow();

        new Timer(1000, new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                if(--countdown == 0){
                    frame.dispose();
                    window.dispose();
                    System.exit(0);
                } else {
                    frame.repaint();
                }
            }

        }).start();

        frame.setContentPane(new JPanel() {

            @Override
            public void paintComponent(Graphics paramGraphics) {
                super.paintComponent(paramGraphics);
                Graphics2D g = (Graphics2D) paramGraphics.create();
                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                g.setColor(new Color(50, 50, 50));
                g.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
                g.setColor(new Color(180, 180, 180));
                g.drawString("Closing in " + countdown + " seconds", 20, 25);
            }
        });

        window.setContentPane(new JPanel() {

            @Override
            public void paintComponent(Graphics paramGraphics) {
                super.paintComponent(paramGraphics);
                Graphics2D g = (Graphics2D) paramGraphics.create();
                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                g.setColor(new Color(180, 180, 180));
                g.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
            }
        });

        frame.setUndecorated(true);

        ((JComponent) frame.getContentPane()).setOpaque(false);
        ((JComponent) window.getContentPane()).setOpaque(false);

        AWTUtilities.setWindowOpaque(frame, false);
        AWTUtilities.setWindowOpaque(window, false);

        window.setAlwaysOnTop(true);

        frame.setBounds(200,200,500,500);
        window.setBounds(600,600,200,200);
        frame.setVisible(true);
        window.setVisible(true);
    }
}
  • 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-03T11:51:22+00:00Added an answer on June 3, 2026 at 11:51 am

    Try this code part, I had used JWindow though

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class WindowExample
    {
        private JWindow window;
        private JLabel updateLabel;
        private int count = 5;
        private Timer timer;
        private int x;
        private int y;
        private ActionListener timerAction = new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                updateLabel.setText("Closing Window in " + count + " seconds...");
                count--;
                if (count == 0)
                {
                    timer.stop();
                    window.setVisible(false);
                    window.dispose();
                }   
            }
        };
    
        private void createAndDisplayGUI()
        {
            final JFrame frame = new JFrame("Window Example");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            frame.setUndecorated(true);
            frame.setOpacity(0.5f);
            frame.addMouseListener(new MouseAdapter()
            {
                public void mouseClicked(MouseEvent me)
                {
                    x = me.getX();
                    y = me.getY();
                    window = new JWindow();
                    JPanel contentPane = new JPanel();
                    JLabel positionLabel = new JLabel(
                        "X : " + me.getX() + " Y : " + me.getY());
                    updateLabel = new JLabel("TImer");  
                    contentPane.setLayout(new BorderLayout(5, 5));
                    contentPane.add(updateLabel, BorderLayout.CENTER);
                    contentPane.add(positionLabel, BorderLayout.PAGE_END);
                    window.setContentPane(contentPane);
                    window.setOpacity(0.5f);
                    window.setSize(200, 100);
                    window.setLocation(x + window.getWidth(), y + window.getHeight());
                    window.setVisible(true);
                    count = 5;
                    timer = new Timer(1000, timerAction);
                    timer.start();
                }
            });
    
            frame.setSize(500, 500);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    
        public static void main(String... args)
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    new WindowExample().createAndDisplayGUI();
                }
            });
        }
    }
    

    And here is the output :

    TRANSLUCENT

    WARNING I AM GETTING

    C:\Mine\JAVA\J2SE>javac -d classes src\OpaqueWindowSSCCE.java
    src\OpaqueWindowSSCCE.java:1: warning: AWTUtilities is internal proprietary API and may be removed i
    n a future release
    import com.sun.awt.AWTUtilities;
                      ^
    src\OpaqueWindowSSCCE.java:68: warning: AWTUtilities is internal proprietary API and may be removed
    in a future release
            AWTUtilities.setWindowOpaque(frame, false);
            ^
    src\OpaqueWindowSSCCE.java:69: warning: AWTUtilities is internal proprietary API and may be removed
    in a future release
            AWTUtilities.setWindowOpaque(window, false);
            ^
    3 warnings
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.