VlcJ Canvas on top - java

I'm using the vlcJ library to play videos in my program from another VLC process (OutOfProcess player). The vlcJ Canvas to play the video is embedded in a Component in a JTabbedPane. When the player is initialized, the video canvas comes to front on top of every other control.
I read about heavy-/lightweight component, so I know, that JRE 1.8 isn't still able to handle heavyweight components correctly, when drawed by another process embedded in lightweight components.
Embedded heavyweight components must belong to the process that
created the frame or applet. The heavyweight component must have a
valid peer within the main process of the application (or applet).
So my question is how to fix this issue, so that the Canvas will not come to front "unasked"?
The tab "Multimedia" hosts the video canvas. Despite another tab is open, the canvas stays on top of everything. When the host tab "Multimedia" is opened once, the video canvas behavave correctly and stays in its tabs.

With the help of #MadProgrammer and #caprica i was able to figure out a workaround: Since I'm using an OutOfProcess Player with vlcJ-pro i can't use the "direct" aproach, because player and canvas are not the same process.
Hide and show the video canvas is also no option, because the component, where the video images are drawn has to be visible all time (otherwise serious exception occur).
So finally i wrapped my video canvas into a JPanel with CardLayout and i switch between an empty pane and the video canvas. Every time a tab with mediaplayer is opened, the video canvas becomes visible, else the empty pane.
This workaround seems to work fine.

Related

Can I place image outside JFrame?

Can I place an image outside JFrame?
I am developing an app, and I wanted to make the Gui good looking and some part of the buttons should go outside. Is there a way to do this?
Yes, but it's not going to be easy, as you going to constantly need to monitor the position of the parent frame in order to maintain the position of the child window.
Essentially, what you can do is create a second, undecorated and transparent window. You would need to align and size the window next to the parent window.
On to this child window, you would need to then add a transparent component which would act as your primary container.
Take a look at How to Create Translucent and Shaped Windows for more details
For example:
How to draw images on transparent window?
How to make a transparent JFrame but keep everything else the same?
Creating a JFrame you can click through
No; the Swing framework doesn't handle painting outside the root component.

Graphics and applets

I am currently working on an assignment and need to create basic controls (buttons) for the Mandelbrot set that will operate as a JApplet. The graphics is initialised in the init() method and a method which draws the Mandelbrot is called in start(). The problem is, I have searched high and low and cannot figure out how to add a GUI to my applet because
I don't explicitly add the mandelbrot to a JPanel , and..
I have no room left it seems to add a GUI because the Mandelbrot takes up the entire JFrame.
I had one idea which was to set the size of the JFrame, set the size of the Mandelbrot graphic to only be say 4/5 of the whole frame, and add buttons to the remaining portion?
Does that sound like a good solution?
Does that sound like a good solution?
No. The panel in which the Mandelbrot is drawn should return a sensible preferred size. Add the rendering panel and the buttons to a layout or groups of layouts using layout padding, borders and button margins for white space.
But I am a little confused by the reference to japplet tag yet the body of the question mentions both JApplet and (twice) JFrame.
An applet has to make do with whatever size it is provided by the HTML (or JS, in the case of the deployment toolkit script) that launches it.
A frame can call pack() on a properly laid out UI and expect to be the smallest size needed to display the components.
General tips
Why code an applet? If it is due to spec. by teacher, please refer them to Why CS teachers should stop teaching Java applets.
For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start. JWS allows the user to launch a JFrame from a link in a web page.
Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them1, along with layout padding & borders for white space2.

Change Jframe Shape

In c# you could change the form shape to be as some picture shape that you draw..
I wonder if there is the same option to do this on jFrame in java? (I'm using netbeans)
and for example this is the picture I want to be used as the jFrame shape
so inside the "phone screen" I want to add some buttons.. is it possible?
See How to Create Translucent and Shaped Windows for details & especially How to Implement a Shaped Window.
Android Look and Feel
Everything on an Android screen is a rectangle. Widgets are rectangles. Launcher icons are 96 x 96 pixel squares. The text under a launcher icon makes them a rectangle.
The screen resolution of a Samsung Galaxy S3 is 1,280 x 720 pixels. The screen resolution of my 22" Samsung monitor is 1,680 X 1,050 pixels. You're going to have to turn the "phone" on its side and use your entire display to get the sharpness of the text on the S3.
This would be a great look and feel for a dashboard application. Your users are probably already accustomed to the smart phone appearance. Obviously, the gestures in your Swing application would have to use a mouse.
GUI Design
First, you create an ordinary JFrame.
Second, you create a drawable JPanel by extending JPanel and overriding the paintComponent method. You would paint the background image on this JPanel, then paint the launcher icons. The launcher icons are BufferedImages created from PNG files, so they can have transparent areas.
The drawable JPanel would listen for mouse clicks. This is so the launcher icons can be moved, and also so the launcher icons can be executed.
The Java application launched would replace the drawable JPanel with it's own JPanel. You would have to follow the Android developer guidelines in developing these JPanels, so your users feel like they're in an Android look and feel. Each application JPanel would have to be 1,280 x 720 pixels.
Your GUI model would hold all of the launcher icons, as well as the positions of these icons for each user. A relational database could hold all of this information so each user would have his or her own display.
Apps / Widgets
I hadn't worked out all the details in my mind, but there would have to be an Apps / Widgets drawable JPanel that shows all of the launcher icons and widgets. The user can drag the launcher icons from the Apps JPanel to the main drawable JPanel.

Identifying monitor applet is running on, in a multi-monitor system

I have Applet with a button running in a browser which when the button is clicked opens a JFrame. I would like to set the JFrame location to be the centre of the screen of whichever monitor the browser was running in. So if they only have one monitor the JFrame will open at the centre of this screen. If they have two monitors and the browser is in the left monitor clicking the button would open the JFrame at the centre of the left monitor. If the browser is in the right monitor display then clicking the button would cause the JFrame to open in the centre of the right monitor's display.
Currently I am using:-
Toolkit.getDefaultToolkit() to get a Toolkit object and then calling Toolkit.getScreenSize() to get the screen size and then working out the centre position from that. This is always based on the left monitor regardless of where the browser is.
Also, I know this could be further complicated if a user happened to have a different resolution between their monitors.
Get the GraphicsConfiguration of the JApplet and then pass that to the constructor of your JFrame. You would also use that GraphicsConfiguration to get a bounding rectangle for centering.
GraphicsDevice will give you info on all screen devices.
It's designed to handle the exact scenario that you need, just take a look at the sample code.
For centering one can normally use JFrame.setLocationRelativeTo(null). Maybe it centers on the default screen? What if the argument is the applet?

Java Applet to Multi Panel Application

I have made a Java game, but it is applet based. I want to convert it into a standalone application. Unfortunately I have 0 knowledge of swing/java applications so I'm not exactly sure where to start and how to get what I want.
My main issue is that the game screen is essentially divided into two parts. The "game screen" and what I refer to as the "dashboard". If you can imagine age of empires, star craft, or any other RTS type of game, that's what the layout is.
So what I want is the screen to have its own graphics panel (all the drawing/animation is done with the graphics and image class) that also has scroll bars in it, that way the size of the game isn't limited to the size of your screen. And I want the dashboard to be it's own separate independent panel, which also uses graphics methods. But in the end, both panels are in the same window.
Is there anyway this is possible?
PS: feel free to request any code or screenshots of the game
Edit: if it is possible, how should I go about doing this?
Simple Swing applications usually based on JFrame class. As i understand, whole game is rendered and not using standard components in UI. Then, roughly, almost no difference between JApplet and JFrame classes. If you used specific JApplet methods for loading resources or something similar, almost all of them would easily replaced with counterparts.
You could create a component class (by extending JComponent) and use it to render main game window. And create another one to render dashboard. Then use BorderLayout as layout manager on JFrame, place main window on center and dashboard on any edge.
There are pretty clear HowTo`s on Oracle site:
How to Make Frames and How to Use Panels.
I think Mersenne's answer covers it pretty well, though I'd consider rendering the game play in a BufferedImage and adding that to (an ImageIcon in) a JLabel in a JScrollPane.

Categories

Resources