How to make a JPanel transparent? Not able to do it with setOpaque(false)

Hi all,
I am writing a code to play a video and then draw some lines on the video. For that first I am playing the video on a visual component and I am trying to overlap a JPanel for drawing the lines. I am able to overlap the JPanel but I am not able to make it transparent. So I am able to draw lines but not able to see the video. So, I want to make the JPanel transparent so that I can see the video also... I am posting my code below
import javax.media.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.lang.Math;
import javax.media.control.FramePositioningControl;
import javax.media.protocol.*;
import javax.swing.*;
class MPEGPlayer2 extends JFrame implements ActionListener,ControllerListener,ItemListener
     Player player;
     Component vc, cc;
     boolean first = true, loop = false;
     String currentDirectory;
     int mediatime;
     BufferedWriter out;
     FileWriter fos;
     String filename = "";
     Object waitSync = new Object();
     boolean stateTransitionOK = true;
     JButton bn = new JButton("DrawLine");
     MPEGPlayer2 (String title)
          super (title);
          addWindowListener(new WindowAdapter ()
               public void windowClosing (WindowEvent e)
                        dispose ();
                        public void windowClosed (WindowEvent e)
                     if (player != null)
                     player.close ();
                     System.exit (0);
          Menu m = new Menu ("File");
          MenuItem mi = new MenuItem ("Open...");
          mi.addActionListener (this);
          m.add (mi);
          m.addSeparator ();
          CheckboxMenuItem cbmi = new CheckboxMenuItem ("Loop", false);
          cbmi.addItemListener (this);
          m.add (cbmi);
          m.addSeparator ();
          mi = new MenuItem ("Exit");
          mi.addActionListener (this);
          m.add (mi);
          MenuBar mb = new MenuBar ();
          mb.add (m);
          setMenuBar (mb);
          setSize (500, 500);
          setVisible (true);
     public void actionPerformed (ActionEvent ae)
                    FileDialog fd = new FileDialog (this, "Open File",FileDialog.LOAD);
                    fd.setDirectory (currentDirectory);
                    fd.show ();
                    if (fd.getFile () == null)
                    return;
                    currentDirectory = fd.getDirectory ();
                    try
                         player = Manager.createPlayer (new MediaLocator("file:" +fd.getDirectory () +fd.getFile ()));
                         filename = fd.getFile();
                    catch (Exception exe)
                         System.out.println(exe);
                    if (player == null)
                         System.out.println ("Trouble creating a player.");
                         return;
                    setTitle (fd.getFile ());
                    player.addControllerListener (this);
                    player.prefetch ();
     }// end of action performed
     public void controllerUpdate (ControllerEvent e)
          if (e instanceof EndOfMediaEvent)
               if (loop)
                    player.setMediaTime (new Time (0));
                    player.start ();
               return;
          if (e instanceof PrefetchCompleteEvent)
               player.start ();
               return;
          if (e instanceof RealizeCompleteEvent)
               vc = player.getVisualComponent ();
               if (vc != null)
                    add (vc);
               cc = player.getControlPanelComponent ();
               if (cc != null)
                    add (cc, BorderLayout.SOUTH);
               add(new MyPanel());
               pack ();
     public void itemStateChanged(ItemEvent ee)
     public static void main (String [] args)
          MPEGPlayer2 mp = new MPEGPlayer2 ("Media Player 2.0");
          System.out.println("111111");
class MyPanel extends JPanel
     int i=0,j;
     public int xc[]= new int[100];
     public int yc[]= new int[100];
     int a,b,c,d;
     public MyPanel()
          setOpaque(false);
          setBorder(BorderFactory.createLineBorder(Color.black));
          JButton bn = new JButton("DrawLine");
          this.add(bn);
          bn.addActionListener(actionListener);
          setBackground(Color.CYAN);
          addMouseListener(new MouseAdapter()
                         public void mouseClicked(MouseEvent e)
               saveCoordinates(e.getX(),e.getY());
     ActionListener actionListener = new ActionListener()
          public void actionPerformed(ActionEvent aae)
                    repaint();
     public void saveCoordinates(int x, int y)
                System.out.println("x-coordinate="+x);
                System.out.println("y-coordinate="+y);
                xc=x;
          yc[i]=y;
          System.out.println("i="+i);
          i=i+1;
     public Dimension getPreferredSize()
return new Dimension(500,500);
     public void paintComponent(Graphics g)
super.paintComponent(g);
          Graphics2D g2D = (Graphics2D)g;
          //g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
          g2D.setColor(Color.GREEN);
          for (j=0;j<i;j=j+2)
               g2D.drawLine(xc[j],yc[j],xc[j+1],yc[j+1]);

camickr wrote:
"How to Use Layered Panes"
http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html
Add your video component to one layer and your non-opaque panel to another layer.Did you try that with JMF? It does not work for me. As I said, the movie seems to draw itself always on top!

Similar Messages

  • How to make a JPanel selectable

    When extending a JPanel and overriding the paintComponent() method the custom JPanel can not be selected so that it gets for example KeyEvents.
    But if I make the new Class extend a JButton it gets of course selected and able to receive for example KeyEvents.
    My question is therefore; what does the JButton implement that a JPanel doesn&#8217;t so that a JButton gets selectable? Or in other words; how to make a JPanel selectable?
    Aleksander.

    Try this extended code. Only the first panel added can get the Focus.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Test extends JFrame
      public Test()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel1 = new JPanel(new BorderLayout());
        JPanel panel2 = new JPanel(new BorderLayout());
        ImagePanel imgPanel = new ImagePanel();
        panel1.setFocusable(true);
        panel2.setFocusable(true);
        panel1.setPreferredSize(new Dimension(0, 50));
        panel2.setPreferredSize(new Dimension(0, 50));
        panel1.setBorder(BorderFactory.createLineBorder(Color.RED,     4));
        panel2.setBorder(BorderFactory.createLineBorder(Color.CYAN,    4));
        imgPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 4));
        panel1.add(new JLabel("Panel 1"), BorderLayout.CENTER);
        panel2.add(new JLabel("Panel 2"), BorderLayout.CENTER);
        getContentPane().add(panel1, BorderLayout.NORTH);
        getContentPane().add(panel2, BorderLayout.SOUTH);
        getContentPane().add(imgPanel, BorderLayout.CENTER);   
        pack();
        panel1.addKeyListener(new KeyAdapter(){
            public void keyPressed(KeyEvent ke){
                System.out.println("Panel1");}});
        panel2.addKeyListener(new KeyAdapter(){
            public void keyPressed(KeyEvent ke){
                System.out.println("Panel2");}});
      public static void main(String[] args){new Test().setVisible(true);}
    class ImagePanel extends JPanel
      Image img;
      public ImagePanel()
        setFocusable(true);
        setPreferredSize(new Dimension(400,300));
        try{img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("Test.gif"), "Test.gif"));}
        catch(Exception e){/*handled in paintComponent()*/}
        addKeyListener(new KeyAdapter(){
          public void keyPressed(KeyEvent ke){
            System.out.println("ImagePanel");}});
      public void paintComponent(Graphics g)
        if(img != null)
          g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);
        else
          g.drawString("This space for rent",50,50);
    }

  • How to make valuation type field not changeable  in delivery tab of PO

    Hai friends,
                    I am new to badis..please guide me to solve the issue...
    how to make valuation type field not changeable  in delivery tab of PO...
    The field shd be in display mode only ...actually...there  a badi has been used before
    to get valuation type from a ztable depending on material and plant...
    Now ..my requirement is that the user shd not change the default value brought from the ztable...

    Hi SRINIVAS,
    You can achieve this from BADI only if BADI is allows you to do this. You cannot achieve everything from a BADI. Check if there is any expoting field in the methods that can be ticked for making the field in display mode. If not then you cannot achieve this from BADI.
    The field you want to default to display is a standard or zfield. If z, then you can changethe attribute of the screen field to Output only.
    Regards,
    Manish

  • How to make a completely transparent button in Flash Builder

    I am making a mobile application, and I am wondering how to make a completely transparent button. I've tried using
    <s:Button x="-5" y="0" width="410" height="1504"
                                    skinClass="spark.skins.mobile.TransparentNavigationButtonSkin" click="navigator.pushView(Sun)"/>
    But it still has one line on the side. I need a way to make it completely transparent.
    Thanks,
         8th grade student

    Try this alpha="0.001"
    Also add useHandCursor="true" and buttonMode="true" if you wish to have the hand cursor appear on hover.
    example  x="10" y="10" width="169" height="54" label="Button" alpha="0.001" useHandCursor="true" buttonMode="true" 
    HTH

  • TS3276 On the left side of the mail page there is an "On My Mac" header with several folders included. One of the folders, in white, is one called "recovered mail" I don't know how this got there and am not able to delete it. Not receiving any email now.

    On the left side of the mail page there is an "On My Mac" header with several folders included. One of the folders, in white, is one called "recovered mail" with 843 messages in it. I don't know how this got there and am not able to delete it. I am also no longer receiving any email now. Help!

    set the wake-on lan on the main computer
    The laptop's too far away from the router to be connected by ethernet. It's all wifi.
    No separate server app on the laptop, it's all samba
    The files are on a windows laptop and a hard drive hooked up to the windows laptop. The windows share server is pants, so I'd need some sort of third party server running. Maybe you weren't suggesting to use Samba to connect to the windows share though?
    I'm glad that you've all understood my ramblings and taken and interest, thanks The way I see it, I can't be the only netbook user these days looking for this kind of convenience, and I certainly won't be once chrome and moblin hit the market.
    Last edited by saft (2010-03-18 20:38:08)

  • Help!!! How to make quicktime plugin do not display on top of the web page?

    Any one knows how to make quicktime plugin do not display on top of the web page??? I've tried to change the zIndex property using javascript, but it doesn't work.
    Because we have some widgets which are required to be moved to anywhere on the page, we use iframe to implement that, so it can display on top of quicktime plugin, but the plugin flickers sometimes when we do some operation on the widget which is on top of it.
    Anyone can helps me? Thanks in advance!!!
      Windows XP Pro  

    > Can you tell me how to set the script so that the
    lightbox image is
    > displayed
    > on mouseover instead of mouse click.
    Check the docs. Trent is usually very thorough in his
    instructions.
    Hint: I haven't studied it but it probably involves modifying
    one of DW's
    built-in Behaviors.
    Walt
    "ducati1" <[email protected]> wrote in
    message
    news:gkb906$qrd$[email protected]..
    > Wow that DW extension is just what I needed.
    > Thanks..
    > Can you tell me how to set the script so that the
    lightbox image is
    > displayed
    > on mouseover instead of mouse click.
    > I currently have the thumbnails set to insert the ALT
    text into a text box
    > on
    > mouse click.
    >

  • Hi! Since I installed Mavericks, all the messages in mail I receive are marked as read, when they're not! Can anyone explain to me how to make them appear as not read, so I notice them? Thank's

    Hi! Since I installed Mavericks, all the messages in mail I receive are marked as read, when they're not! Can anyone explain to me how to make them appear as not read, so I notice them? Thank's

    I don't know if it will work, but try rebuilding the mailbox. This can take awhile if you have a lot of mail.
    Rebuild mailbox

  • I have an old mpg video file, taken with a very early model "smart phone", that opens and plays fine in my newly "rebuilt" iPhoto library. I cannot open, edit it or share it with any other software. How can I fix it, to be able to do anything with it?

    I have an old mpg video file, taken with a very early model "smart phone", that opens and plays fine in my newly "rebuilt" iPhoto library. I cannot open, edit it or share it with any other software. How can I fix it, to be able to do anything with it?
    Detail:
    I've recently purchaced a 4TB Thunderbolt drive to store my "vast" music and photo libraries. iPhoto had an issue reading the moved library, so I bought and used iPhoto Library Manager to "rebuild" it. Apart from much of the original data such as date taken & camera used etc, it appears to be working well. The aforementioned mpg video was taken some 9 years ago, using an early model "iMate" smart phone, and opens and plays fine on iPhoto, but I cannot open it with anything else, (I've tried iMovie, VLC players, Wondershare and Handbrake) nor can I share it. I just want to edit it, and share it with family.
    Any help would be appreciated...

    No - not iMovie, VLC, Wondershare or Handbrake... Quick time starts with a "CONVERTING", then I get
    I've looked at the "tell me more" links, tried downloading some of the movie players there. I'm begining to think the file is corrupt.
    Thanks for getting back to me again though - appreciate it...

  • LR 4 RC2 ...vexing problem, 3 sessions with support and still not able to find? With all settings re

    LR 4 RC2 ...vexing problem, 3 sessions with support and still not able to find? With all settings reset and running a test catalog a raw image when opened in develop will when imediately going back to library view show a significant color shift in red, orange and purple but only in images with significant content in those colors. at first the culprit appeared to be camera calibration default but not reproducable. The problem exists even when opening older images from months ago?  Also if second screen running in loupe mode the image is not shifted.
    Any ideas please
    Dave

    Jim01403, Geoff and others...I'm new here so I'll need a little time The thread is very interesting, populated by serious mature people, how refreshing! It clearly is part of what i'm experiencing and is answered answered here...thank you. My main problem is still the significant color shift between develope and library modules. I'll attach one from each so you and others can see. Unfortunately the library version is the bad one so printing is now very problematic...Note, this occurs in either single or with second monitor on the library version is displayed. I have reset virtually everything and wonder if a cache is not updating or color space is not matching? A symptom/detail worth noting, when switching to library mode, the correct image is displayed for about a second then it jumps to what you see in the examples. As if the library module starts to rendering from develope settings then jumps tback to the original inedited preview??
    Maybe just go back to 3.6 and tread water till 4.1 is fixed?
    Dave

  • I'm not able to send emails with mail.ru. Receiving and reading is not a problem. When I create a email with mail.ru its not possible to send it although its stored in my mail.ru account as "still to be send". What can it be??

    I'm not able to send emails with mail.ru. Receiving is not a problem. Creating a mail is also not a problem and the mail will be stored at mail.ru as still to be send, only problem is its not possible to send. I noticed the buttons for sending change colour when used but they don't perform. What it is?

    Don't know what changed, but all of a sudden able to send emails by mail.ru ...... sorry for bothering.

  • Since uninstalling / reinstalling iTunes I am not able to sync iPhotos with my Apple TV with the following warning message stating that this is due to a 'problem on your computer. The disk could not be read from or written to'. Please help!

    Since uninstalling / reinstalling iTunes I am not able to sync iPhotos with my Apple TV with the following warning message stating that this is due to a 'problem on your computer. The disk could not be read from or written to'. Please help!

    Welcome to Apple Discussions!
    Is all the software on your computer up to date?
    iTunes
    iPod Updater
    Also, try The Five R's
    btabz

  • I am not able to add videos to itunes. So I am not able to sync them with my IPhone4s. I ve tried: dragging to itunes, minimize file name of mp4, adding by file/folder still not adding. WHY? Please help.

    I am not able to add videos to itunes. So I am not able to sync them with my IPhone4s.
    I ve tried:
    dragging to itunes,
    minimize file name of mp4,
    adding by file/folder, but still not adding.
    WHY? Please help.

    This is very serious. Your computer got infected with ransom malware, Cryptowall.
    Go here for further info.
    CryptoWall 2.0 Anything Good about Buying you Keys? - General Security
    CryptoWall and DECRYPT_INSTRUCTION Ransomware Information Guide and FAQ

  • In P6 version7 not able to copy project with the baseline.

    Hi,
    In P6 version 7 it is not able to copy project with the baseline. It copies only the schedule.
    Please help.
    regards,
    Baber.

    Tried the solution from another thread but did not work completely (as warned) - the workaround didn't quite work for me either:
    https://discussions.apple.com/thread/1398462?start=0&tstart=0
    Ended up taking a backup, did a fresh install, created the account as the first one so that it gets the same UID as the other Mac (on which my account was the first) and restored my data - was painful but finally on track.

  • Icloud backup - my ipad is hung with the dialogue box saying "this iPad hasn't been backed up in 4 weeks. Backup happen when this iPad is plugged in locked and connected to WiFi". Even after doing what is said, I am not able to do anything with the iPad -

    My ipad is hung with the dialogue box saying "this iPad hasn't been backed up in 4 weeks. Backup happen when this iPad is plugged in, locked and connected to WiFi". Even after doing that, I am not able to do anything with the iPad - neither able to reboot nor able to get to the homescreen. The dialogue box doesn't go at all even after pressing OK a hundred times. I treid tacking the back up through itunes and through 3G conncetion but of no avail. Please help

    I too have been having this issue since about 12/14.  That is around the same time I got the Ipad for my kids.  I am unsure if it is related.  I have tried logging out of icloud/deleting it and trying again.  Removing most of the apps to sync.  I reset my router.  All of the attempts have produced zero results.  I will be anxiously watching this thread for some help.  Good luck to you also

  • TS4022 I am not able to use iclould with Internetexplorer.

    I am not able to use iclould with Internetexplorer.  I was able to until November.  I have been way and on my return I can not even log in usin IE.  I can using Chrome.  I am an IE user so would like help please?

    This may not work for everyone, but I solved this problem by clicking on the file name in sharepoint, not the document icon to the left of the name. This then brought up the various options, including checking out, editing, version history etc. It seems obvious but I have only just realised this!

Maybe you are looking for

  • Who runs a regular osx lion on mac mini server ?

    Wo runs a regular OSX lion (not the server edition ) on a mac mini server without any problems ? I have a late 2011 mac mini server with a regular OSX lion 10.7.3 latest updates, wich keeps freezing unattended at certain times. Wish to hear if this s

  • Custom Component Classes

    Hi all I have been learning flex for a few months now and absolutely loving it! But there is one thing I can't get my head round. I use to be a Flash user mostly which is probably why I am getting confused.... I want to be able to make custom compone

  • How to apply 1/3 octave bandpass filter of about 10Khz on a signal

    I am unable to retrieve the time signal after doing the 1/3 octave analysis.

  • Cellular data tab missing

    I have an ipad 2 and subscribe to a cellular data plan.  Upgraded to ios 5.1.1.  Now the "cellular data" tab is missing from settings.  Have tried to restore but no luck.  Does anyone know how to get the cellular data tab back?  Thanks

  • Multiple paths in FILE_DATASTORE path attribute

    Hi, I want to index a column that holds file names spread across multiple directories on HD. The documentation says this can be done by separating paths with a ':'. I tried the following but didn't work (DRG-11513): BEGIN ctx_ddl.set_attribute('IE2.I