Swing Works different on different Platform - java

I have made a Screen Recorder using Java Swing and Xuggler 5.4. I have developed it in Windows 8 64 bit. It's working excellent for Windows. But at client side on Linux's environment , nothing is working. I have searched thoroughly but not getting any solutions. I have checked this thread , but it didn't work for me.
Then I tried to create simple Transparent window in Linux but it's also not working. I was not able to click through the Resizeable Panel. I have used the same JRE version (1.7) for both. Have I miss understood Java's Cross Platform Support as far as Swing is concerned?
Please Give Me Some Advice...

I have always found logging to be the best debugging tool at your disposal! Many a times, java debuggers take you into APIs where you need not go every time. Logging values of your variables, and generic 'I have reached till this point' statements make life a lot easier.
So, I suppose you have ample logging done in your code. That could give you clues on what's happening on your client's system.
Are the right environment variables set? Are they pointing to the correct Java versions you need.
If there are some specific Screen capturing requirements(plugins / modules / API) your code has, are they available on the Linux m/c?
Like #MadProgrammer said, in the end, Java has to talk with the native graphics APIs to render your screen.
I would try to debug it in this way -
Check whether my main screen loads or no(by disabling the screen capture functions for a while).
if not, dig deeper.
Check whether all necessary components for capturing screen(audio and video) are available.
Check whether the code is being run with appropriate permissions to control the h/w devices you may need.

Related

Get Image from an Application

Sorry, this question is pretty broad, but I haven't a clue how to go about it.
In Java, how can I get whatever a Windows application is displaying in the form of an Image?
I'd like the contents of the Image to include just a frame from one application window, not a whole monitor.
I think getting the application window from the title of the window may be a start, but does Java even have access to the GUIs of other processes?
The best you can do in pure Java is to use the Robot class to capture a specified rectangle. The following Q&A show how ... for the case where the rectangle is the entire screen.
Screenshot capture in Window 8 OS
(This should work for all non-headless Java SE platforms.)
That's the easy bit. The hard bit is figuring out what rectangle to screenshot. The Java libraries provide no APIs for finding information about the screen locations of "other" applications. To find that kind of information, your Java application would need to interact with the native OS via a native library or an external utility command. This will inevitably be platform specific ... meaning that it will break for Mac and Linux, and possibly for other versions of Windows as well.
I wouldn't try to do this in Java at all. Instead, I would look for an OS-specific screenshot application that can be run as an external application; e.g. using Process.exec. Alternatively, I'd figure out how to write such an app, in (say) C#.
I think getting the application window from the title of the window may be a start, but does Java even have access to the GUIs of other processes?
Nope and nope.

How can I make it so Eclipse automatically updates my code in a window as I edit it?

How can I make it so Eclipse automatically updates my code in a window as I edit it? I've seen the feature before in youtube videos but I cannot find it. For example : I change a JApplet rectangle width from 20 to 10, I want to see it update immediately.
I've seen Notch do this on development videos (Minecraft), it is awesome but I don't know exactly how he does it.
-- EDIT --
This has been bugging me so I went and googled "how does notch code" and found this on a blog page https://gun.io/blog/what-i-learned-from-watching-notch-code/. It doesn't say exactly how it was done but gives a good hint (HotSwap) and makes it seem like he set it up himself without external software. Here's the most relevant section:
Incredibly Fast Testing
He began by building the engine, and to do this he used the ‘HotSwap’ functionality of the Java JVM 1.4.2, which continuously updates the running code when it detects that a class has changed.
When building the engine, Notch wrote a function which would continuously pan the camera around and clip through the walls and keep the view on top, so he could make changes to the code and see the effects they made in real time. I’m used to testing by writing a function, building it, installing it on the device I’m testing on, and then seeing the result, which can take up to a minute at a time, so it’s easy to see how HotSwapping could save a lot of development time.
--- ORIGINAL POST CONTINUED ---
I get a similar effect by using groovysh though, works smoothly and can use all your java classes as is.
What I'll usually do is write all my code in java, then go and fire up "Groovysh" where it will give you a little window to enter commands (You may have to ensure the classpath works correctly outside of eclipse). I can then "new" any of my classes and call methods on them one line at a time. When you do myFrame.setSize([100,100]) you will see it change immediately.
A good test is to just run groovysh and type something like:
import javax.swing.*
f=new JFrame()
f.setVisible(true)
f.setSize(100,100)
or the groovier version:
f=new JFrame(visible:true, size:[100,100])
and you will see your frame resize on the screen. You can even drag it bigger and then do something like:
println f.getWidth()
to show your new width. It's fun to interact this way but it's more complicated if you want to actually change your class definition and see it pick up the change, I have no idea how Notch did that. I looked into it a little--it's possible he was using something like JRebel
It requires something special since you would have to dynamically reload the classfile into your running system on every save--something that should have serious classloader issues.
By the way there is also a way to get your Java program to throw out a little GroovyConsole which will allow you to inspect and modify all the variables in your running code (but again you can't replace definitions of existing classes).
Also see answer here:
Change a method at runtime via a hot swap mechanism

java applet using Next-generation plug-in

I have a web application (struts 1.3, Weblogic 10.3.0, Toplink, Oracle) that has a Java applet which isn’t working in the browser (IE7/8) when the Next-Generation Plug-in setting is enabled in the Java control panel but works fine when it’s disabled. The trouble is that this setting is set to disappear in an upcoming Java release meaning that my users would have to keep using Java 1.6_xx on their workstations as they are currently. I have little influence over which version they use because they are all governed by their local IT departments across the country. So, either I have to find a simple fix to allow the Next-Generation setting to work, or we have to look at replacing/rewriting the applet with something else (but would be a last resort due to funding constraints), most likely something AJAX-friendly so as to avoid the need for a plugin. This application is quite old, written around 2001 before AJAX was really around.
The main window has a left, right, and top frame (JSP’s), as well as a center frame which is where the applet is. The applet has a main content area in the middle and a lower panel at the bottom which has some buttons. The buttons tell the content area (which is basically a treegrid) what to do (Save, Copy, change status, etc ). When I press one of the buttons the entire window (surrounding frames plus the applet itself) repeat inside the area where the applet is. It’s like a kaleidoscope or like a repeating fractal pattern kind of thing, or like when you take a picture of yourself in the mirror and you see the room repeated over and over in the mirror. In this case it repeats for each button press and the repeated set gets smaller each time. Weird!!
So, based on my research, the Java Next-Generation plugin works differently by allowing more than one process or thread whereas the classic plugin only uses a single thread. So my suspicion is that a new process is being spawned for each button press. I tried using the “separate_jvm” applet parameter but it made no difference whether it was set to true or false. I don’t see any other applet parameters which seem to be relevant.
Another idea I had is that maybe it’s something to do with the JSP frameset, maybe something like “target=_top” needs to be added somewhere…but I’m not sure how this relates to applet threads if at all.
Anyone have any suggestions, ideas or experiences that might help?
you can use velocity to handle these type of problem and it will also help you for future enhancement also.
The problem is not related to version of IE but rather to version of Java. Below excerpt from letter of certificate provider (they took it from some forum, so direct link to source cannot be provided):
For JDK version higher than 1.6.0 and below 1.6_15, you can just
clear all kinds of cache in web browser, java console and java control
panel. Then it should works fine!
For JDK version between 1.6_15 and 1.6_30, you should disable the "next-generation java" option in java control panel.
For JDK version higher than 1.6_30, you should turn on "next-generation java" option in java control panel.

MacOS Java 6 mishandles AppleDisplayScaleFactor when set globally, and ignores it entirely when set application-specific

Later versions of MacOS (> 10.5?) support a spiffy property, AppleDisplayScaleFactor - the scale factor for an application window, which can be set either globally, or for a specific application (identified by the CFBundleIdentifier in the app's info.plist - as I understand it).
BUT... my Java Swing application is a mess when I use this value globally - clicks don't match up with buttons, bad screen painting and so forth - and the same thing happens running JavaSoundDemo. And when I try to use it in a app-specific manner it is never used at all (I tried a variety of "identifiers" for the app - CFBundleIdentifier for the app, for the JVM, and the Main class, which is used as the title for the JVM window).
I'm just hoping that some brave and clever soul has figured out how to make this actually work - the Apple docs on "Resolution-Independent Display" claim that Java simply does everything for you. Perhaps this really should be a bug report to Apple - thanks in advance.
I've found that AppleDisplayScaleFactor doesn't work across all applications (such as Flash within a browser). So it doesn't surprise me that it doesn't work properly with Java Swing.

Adding a contribution to the windows task bar in java - similar to laptop battery widgets

I am trying to make a contribution to the windows task bar so when i minimize my app it docks itself into the windows task bar , the best way of describing this is by looking at a picture I have drawn:
If anybody knows if this is possible or how to do it please let me know.
I am well aware of the ability to add an icon to the system tray - but this is slightly different.
Thanks in advance,
Andy
You should probably have to use JNI or JNA to achieve this - wrapping the native windows API seems like the most viable idea. It'll greatly diminish the value of using Java, however - using JNI/JNA should always be considered last resort...
Take a look at SWT. This will definitely be a platform specific solution but I am assuming this isn't an issue for you.
SWT (Beginning with 3.6 which just went gold) has a TaskBar class and corresponding TaskItem classes for each item in the TaskBar. I don't think the TaskItem class is going to be powerful enough to do what you are asking for, but by looking at the source it will provide you insight into the low level Windows calls that you can access to get this done.
The SWT version for Windows will have a low level platform specific API that should get you where you want to go. Basically they have done all the JNA/JNI work for you. I am not a Windows programmer so I can't give you more details, but hopefully this will point you in the right direction.
You just need to use the System Tray functionality available in Java 6.
If you look at the More Information section at the bottom of that page it has links to the System Tray API and an example project.
Could you hide your application on minimize and then add an icon for it to the system tray that, when clicked, unhides your application?

Categories

Resources