How to change display settings programically with java? - java

Is it possible to alter (change/update) display settings (configuration) in Windows XP using Java programming language?
I would like to do something like this:
Display[] displays = WindowsXPSystem.getDisplays(); //get all available displays (monitors). assume there are currently two monitors connected
Display d0 = displays[0]; // the first is 24" and is positioned on the left
d0.setPrimary(true); // and it should be primary, so all new windows open on it.
d0.setSize(new Dimension(1920,1080)); //update screen size (resolution)
d0.setPossition(0,0); //and position it on the left
Display d1 = displays[1]; //second monitor is also present
d1.setSize(new Dimension(1440,768)); // and it's 14.1" laptop's display
d1.setPossition(1920,332); //it's positioned on the right
Any ideas/suggestions/APIs how to update display settings with Java?

I think this is not possible with plain Java. Have a look at this question here:
Detect and Change display resolution permanently using java
as stated there, it's maybe possible to use any native Libraries through JNI (Java Native Interface) which kind of wraps native Libraries. But you will loose your platform independency then.

There is no plain Java solution to your problem. The function is way to specific for a generic implementation.
You could however, if you really need to implement this use a JNI library, that wraps the Windows functionality of adjusting the screen resolution.

Related

3 dots java title border

does anyone know how to remove those 3 dots from java components?
my problem : a java widget with a title border which, after resize, keeps adding those 3 dots.
I would want for it to display the truncated title which fits that given area.
I managed to set its justification to the left but those 3 dots keep reappereaing...
or, at least, where, in java library, are those 3 points drawn? I searched through java libraries and couldn't fin it.
This happens using java 1.7
You'd normally do that in the UI classes. Here's a similar question: Java JLabel/JButton: on some systems I get "..." (an ellipsis) and on some systems I don't. how can I force to disable the ellipsis at all?
It is not Java or Swing who display the three dots (the "ellipsis"), it is the underlying OS (Windows, Linux ...).
The Java just sets the native window title property.

Java : How to draw graphic object?

I am developing a small desktop application in Netbeans. The application is complete and working fine. A small description of application is as follow:
The application is basically an object manager, where user add new object, remove old objects and connect object with each other. What i did is that i simply add 3 panel and change its type to titled border. One for Add object one for remove and one for connect.
Status:
Every thing is working fine as expected.
What Left:
In order to make UI more appealing i added a new panel at the end and called it "Object Viewer". I am planing to visualize the steps which user performs e.g
If user add an object then i that pannel i will daraw a little
circle and fill it with green color
Similarly if user remove some object then again i will draw another
cricle and fill that with red
And when user connects two object then i will draw two circle and
connect them with a dotted line
This is my first java application, i only want to know how do i acheive this task. Some links or experience are highly appreciated
As for custom painting in swing, have a look here: http://download.oracle.com/javase/tutorial/uiswing/painting/
However, I'd suggest using a graph visualization library like JUNG etc. Using this you'd basically only have to define your object graph.
You can either do that manually with Java 2D, which I don't recommend, or, since you are using Netbeans (and I assume the Netbeans Platform, but this is not required), I would strongly suggest looking at the Netbeans Visual Library. It can do exactly what you want.
As Nico Huysamen said you can do that with Java 2D. But because it's your first Java application I strongly recommend to do it manually with this lybrary in order to understand how higer level lybraries work.

Java: How to get the scrolling method in OS X Lion?

Since OS X supports the "natural scrolling", my applications works wrong. The natural scrolling is made for scroll panes, which I really like. But, when I want to zoom in/out, it works wrong. So, what I want to do is check the scroll method for OS X.
If it is "natural" I'll take the opposite of the scroll values from MouseWheelEvent.getWheelRotation() to make my zoom in/out behavior feel correct.
So, in short: How to know if OS X uses natural scrolling or not?
Found a solution.
First, you need a library to read .plist files. I used this one.
Than you can easily read in the GlobalPreferneces.plist (checked with fseventer which file is changed when changing the scroll option) to find out which kind of scrolling is enabled like this:
try {
File globalPref = new File(System.getProperty("user.home") + "/Library/Preferences/.GlobalPreferences.plist");
NSDictionary dict = (NSDictionary)PropertyListParser.parse(globalPref);
NSNumber pref = (NSNumber)dict.objectForKey("com.apple.swipescrolldirection");
if(pref.boolValue()) {
//natural scrolling is enabled
}
} catch (Exception ex) {
System.out.println("Faild to parse plist: " + ex.getMessage());
}
Take a look at Mike Swingler's answer on the java-dev mailing list. There is a whole thread about it.
As Apple has dropped Java, I don't think that there is built in method to detect if natural scrolling is enabled. However, you could read in in the .plist files for configuring mouse/touchpad behaviour (which is a basic xml file) and look for the property to enable natural scrolling is set to true or false.
You can find the required .plist files here:
User/Library/Preferences/ <- This folder is hidden in Lion!
com.apple.driver.AppleBluetoothMultitouch.mouse.plist
com.apple.driver.AppleHIDMouse.plist
Edit:
You can't read in a plist file with the standard Java Framework, as since Mac OS 10.4 all .plists are saved in binary format. See my other answer for a correct solution.

Signature capture on windows mobile java application

The company I work for has an java application that runs on esmertec jbed JVM on windows mobile 6.
There is a requirement to capture a user's signature as part of some new functionality. One option is to try and implement this in java. This has been tried previously and has been found to be a bit slow.
I think the better option would be to get a native component to handle the drawing of the signature and save it to file. Does anyone know of a component that I would be able to use?
Creating our own component is an option as well but if there is one available already, I would prefer to use that.
For completeness, I'll answer my own question.
I could not find an existing component that done this. We ended up writing some c++ code that would handle this.
The code would get a handle to the Java canvas and register our own callback function with it. This callback function would record any mouse movement within the canvas and draw a line when necessary (either on mouse up or after a number of points had been drawn). Once the user leaves the screen we would save the canvas to file and re-register the original canvas callback function.

How do you specify to display a diamond in a NSMenuItem (minimized window indicator)?

I'm creating a JNI to display an application wide menu bar instead of the JFrame specific one. This allows me to keep a menubar displayed even when no JFrames are present. I've hit a small snag, in my window menu I can't figure out how to display a diamond for the windows that are minimized. As far as I can tell in the standard API there's only three states available On, Off, and Mixed where mixed is a dash. Is there a way to show the minimized diamond using standard API? Or am I going to have to create a diamond image and use that?
AppKit isn't using a public API to get this image. It's using _NSGetThemeImage which pulls an image out of the old HIToolbox Appearance Manager theme resources and converts it an NSImage. I wan't able to find an equivalent public API.
If you want to mimic how AppKit does it, use:
NSImage* _NSGetThemeImage(int num);
[menuitem setState:NSOnState];
[menuitem setOnStateImage:_NSGetThemeImage(155)];
Better yet, use this code to grab the NSImage, save it to a TIFF file, and then include that TIFF in your program. That way you avoid using private APIs in the shipping code. I doubt Apple would complain that you're stealing their diamond. ;)

Categories

Resources