Problem with JPanel and JComponent

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Problem with JPanel and JComponent

 
0
  #1
May 27th, 2009
Iam using an AWT component. Did a little research but cannot find anyway I can make my player return a JComponent..tried this casting but Iam getting an exception at the line.
  1. ((com = (JComponent)p.getVisualComponent()) != null)

I also got to see something about mixing SWING with AWT so I decided to take out AWT completely but i seem to get errors with FlowLayout, and ActionListener..PS Iam using swing panels and frames and only used the AWT for the component and listeners..

This is what I tried with the image part
  1. imageLabel=new JLabel(new ImageIcon("optic.jpg"));
  2. imageLabel.setHorizontalAlignment(JLabel.CENTER);
  3.  
  4. mainPanel.setEnabled(false);
  5. mainPanel.setOpaque(false);
  6.  
  7. otherPanel.setBackground(Color.black);
  8. otherPanel.add(imageLabel,BorderLayout.CENTER);
when a button A is clicked the mainPanel is supposed to display the webcam image, which works well. when button B is pressed, this image displays but not correctly. after a resize of the window, it then displays as needed on the frame. however, when button A is pressed again, the frame does not display anymore..hope this helps abit
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,197
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Problem with JPanel and JComponent

 
-1
  #2
May 27th, 2009
  1. ((com = (JComponent)p.getVisualComponent()) != null)
What you trying to achieve with this line? Are you trying to assign JComponent to com variable if result is not null?

I do not think second part sufficient to locate problem.

PS: It is not recommended to mix SWING and AWT.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: Problem with JPanel and JComponent

 
0
  #3
May 27th, 2009
sorry about that...I was trying to use a JComponent instead of Component since the getVisiaualComponent() method is not availble with JComponent...PS these are two diffrerent problems
prob 1- using JComponent instead of Component with a player or processor in JMK

prob-2
how to place the frames captured by my webcam on my JPanel correctly since the captured data appears infront of the JPanel i.e if I click on the menu bar in my panel, the list appears behind and not at the front
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC