943,600 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 365
  • Java RSS
May 27th, 2009
0

Problem with JPanel and JComponent

Expand Post »
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.
java Syntax (Toggle Plain Text)
  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
java Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
May 27th, 2009
-1

Re: Problem with JPanel and JComponent

Java Syntax (Toggle Plain Text)
  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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,653 posts
since Dec 2004
May 27th, 2009
0

Re: Problem with JPanel and JComponent

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
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: My Postings
Next Thread in Java Forum Timeline: function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC