import javax.swing.*; 
import java.awt.*; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 

public class TransparentDialogTest 
{ 
    public static void main ( final String[] args ) 
    { 
        final JFrame frame = new JFrame ( "Dialog test frame" ); 
        final JButton button = new JButton ( "Show dialog" ); 
        frame.add ( button ); 
        frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE ); 
        frame.pack (); 
        frame.setLocationRelativeTo ( null ); 

        final JDialog dialog = new JDialog ( frame, "Sample dialog" ); 
        final JLabel label = new JLabel ( "Sample dialog content" ) 
        { 
            protected void paintComponent ( Graphics g ) 
            { 
                g.setColor ( Color.RED ); 
                g.fillOval ( 0, 0, getWidth (), getHeight () ); 

                super.paintComponent ( g ); 
            } 
        }; 
        label.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) ); 
        dialog.add ( label ); 
        dialog.setUndecorated ( true ); 
        dialog.setBackground ( new Color ( 255, 255, 255, 0 ) ); 
        dialog.pack (); 

        button.addActionListener ( new ActionListener () 
        { 
            public void actionPerformed ( ActionEvent e ) 
            { 
                final Dimension size = dialog.getSize (); 
                final Point los = button.getLocationOnScreen (); 
                dialog.setLocation ( los.x + button.getWidth () / 2 - size.width / 2, los.y + button.getHeight () ); 
                dialog.setVisible ( true ); 
            } 
        } ); 

        frame.setVisible ( true ); 
    } 
} 
