Video Swing JPanel Within SWT View
I'm building an Eclipse RCP application. I want to embed a video feed on one of the views. I'm using the Java Media Framework to build the video feed. Yes, my job requires me to be a masochist.
When I run my video code as a stand-alone Swing application, the video feed panel (a Swing JPanel
) displays at the correct 320 x 240 pixel size. When I run the same code in my Eclipse RCP using the SWT_AWT class, the video feed panel is reduced to 80 x 60.
I've tried setPreferredSize
a开发者_如何学编程nd setMinimumSize
on the Swing video feed panel. Nothing changes.
I've tried setBounds
and setSize
on the SWT composite. Nothing changes.
Has anyone embedded a Swing video feed in an SWT view?
Has anyone embedded a Swing component in an SWT view, and specified the size of the Swing component?
I finally figured out how I could "trick" SWT into producing a video feed of a more reasonable size.
I displayed a JPG image of the correct size, then overlayed the image with the AWT/Swing code.
Here's the code I used:
Composite videoComposite = new Composite(panel,
SWT.EMBEDDED | SWT.BORDER | SWT.NO_BACKGROUND);
videoComposite.setLayout(new FillLayout());
videoComposite.setLayoutData(new GridData(
SWT.CENTER, SWT.CENTER, true, true, 1, 1));
CLabel videoImage = new CLabel(videoComposite, SWT.SHADOW_IN);
videoImage.setImage(dummyVideo);
final Frame frame = SWT_AWT.new_Frame(videoComposite);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JApplet applet = new JApplet();
applet.setFocusCycleRoot(false);
applet.add(rabidPhoto.getVideoPanel(false));
frame.add(applet);
frame.pack();
frame.setVisible(true);
}
});
First, I defined the SWT Composite.
Next, I defined an SWT CLabel to fill the Composite. I used a CLabel because I use CLabels throughout the rest of the SWT view. dummyVideo
is a JPG that I created. The JPG is 240 x 180 pixels.
Then, I defined the AWT Frame, and filled it with the Swing video panel. Defining a JApplet first is a tip I picked up from the Eclipse web site.
Using the JPG is like using magic numbers in program code, rather than defining them as fields. But at least the JPG trick worked.
精彩评论