Skip to main content

Fullscreen Image Dual-Head

4 replies [Last post]
Anonymous

Hi everybody,

I'm working from within matlab and want to display images fullscreen
(no-titlebar, scrollbars ect) on my secondary monitor.
I found this piece of matlab code written by Pithawat Vachiramon:

function fullscreen(image,device_number)

ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
gds = ge.getScreenDevices();
height = gds(device_number).getDisplayMode().getHeight();
width = gds(device_number).getDisplayMode().getWidth();

if ~isa(image,'uint8')
error('Image matrix must be of UINT8 type');
elseif ~isequal(size(image,3),3)
error('Image must be NxMx3 RGB');
elseif ~isequal(size(image,1),height)
error(['Image must have verticle resolution of ' num2str(height)]);
elseif ~isequal(size(image,2),width)
error(['Image must have horizontal resolution of ' num2str(width)]);
end

global frame_java;
global icon_java;
global device_number_java;

if ~isequal(device_number_java, device_number)
try frame_java.dispose(); end
frame_java = [];
device_number_java = device_number;
end

if ~isequal(class(frame_java), 'javax.swing.JFrame')
frame_java =
javax.swing.JFrame(gds(device_number).getDefaultConfiguration());
frame_java.setUndecorated(true);
icon_java = javax.swing.ImageIcon(im2java(image));
label = javax.swing.JLabel(icon_java);
frame_java.getContentPane.add(label);
gds(device_number).setFullScreenWindow(frame_java);
else
icon_java.setImage(im2java(image));
end
frame_java.pack
frame_java.repaint
frame_java.show

This clearly uses Java's 2D API. However it doesnt work. I can get it to
display an image on my primary monitor but not on the secondary monitor.
gds = ge.getScreenDevices(); should give me an array of attached
devices and it seems to do that as with two monitors i get an array of two.
However once I parse these through to the height and width check I get
resolution of my primary device returned for both values of gds.
If I use gds=ge.getDefaultScreenDevice(); the size of the array is 1 as
it should be and also the video resolution then corresponds with which
monitor i have set as default in windows. Any ideas on how to overcome
this problem and make sure that my loaded image is displayed on the
secondary monitor ?

Cheers,
Peter Zoon

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rah003
Offline
Joined: 2004-05-26

As far as I know there was a bug with Java 1.4.2. Should have been fixed in Mustang (1.6). What version are you running it on?
For details see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5101561

Cheers.

Peter Zoon

I'm running the latest version and updated to latest beta release but my
problem persists. Maybe the bug got back in in a later release ?

Cheers
java2d@JAVADESKTOP.ORG wrote:
> As far as I know there was a bug with Java 1.4.2. Should have been fixed in Mustang (1.6). What version are you running it on?
> For details see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5101561
>
> Cheers.
> [Message sent by forum member 'rah003' (rah003)]
>
> http://forums.java.net/jive/thread.jspa?messageID=194858
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

rah003
Offline
Joined: 2004-05-26

Strange. Can be also mathlab problem. Could you try to compile and run following:
[code]
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;

import javax.swing.JWindow;
import javax.swing.JLabel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class FullScreen {
public static void main (String[] args) {
// there's a bug that is supposed to be fixed in 1.6 ... no 2nd screen fullscreen before than ... oh well
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
Click click = new FullScreen().new Click();
for (int j = 0; j < gs.length; j++) {
if (args.length > 0 ) {
if (args[0].equals("0") && j != 0) {
continue;
}
if (args[0].equals("1") && j != 1) {
continue;
}
}
GraphicsDevice gd = gs[j];
JWindow window = new JWindow(gd.getConfigurations()[0]);
window.addMouseListener(click);
window.setLayout(new GridLayout());
window.add(new JLabel("Screen:" + j, JLabel.CENTER));
System.out.println(j + " supports full screen: " + gd.isFullScreenSupported());
gd.setFullScreenWindow(window);
}
}

class Click extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
System.exit(0);
}

}
}[/code]

You should see the grey screen and text "Screen X" in the middle of the screen giving you the number of the device. If the problem persists you will see the grey rect and label only on one of the screens. If it works, both of your screens will be grey. To close it just click the mouse. If the pure java (above) works then the problem is likely related to mathlab (maybe references old JVM somewhere???), if not then posting your exact configuration (JVM version, OS version) would help.

Cheers

Peter Zoon

Not exactly sure on how to execute the code you attached, but you are
right about matlab having its own JVM. And that is indeed 1.4.2 can
update it to 1.5.10 but then bug still remains. When upgrading to 1.6
matlab spits out a bunch of errors. so seems matlab is the limiting
factor here and not java. Will try and find out if I can get matlab to
only run 1.6 for my script.

Thanks a lot
java2d@JAVADESKTOP.ORG wrote:
> Strange. Can be also mathlab problem. Could you try to compile and run following:
> [code]
> import java.awt.GraphicsDevice;
> import java.awt.GraphicsEnvironment;
> import java.awt.GridLayout;
>
> import javax.swing.JWindow;
> import javax.swing.JLabel;
> import java.awt.event.MouseAdapter;
> import java.awt.event.MouseEvent;
>
> public class FullScreen {
> public static void main (String[] args) {
> // there's a bug that is supposed to be fixed in 1.6 ... no 2nd screen fullscreen before than ... oh well
> GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
> GraphicsDevice[] gs = ge.getScreenDevices();
> Click click = new FullScreen().new Click();
> for (int j = 0; j < gs.length; j++) {
> if (args.length > 0 ) {
> if (args[0].equals("0") && j != 0) {
> continue;
> }
> if (args[0].equals("1") && j != 1) {
> continue;
> }
> }
> GraphicsDevice gd = gs[j];
> JWindow window = new JWindow(gd.getConfigurations()[0]);
> window.addMouseListener(click);
> window.setLayout(new GridLayout());
> window.add(new JLabel("Screen:" + j, JLabel.CENTER));
> System.out.println(j + " supports full screen: " + gd.isFullScreenSupported());
> gd.setFullScreenWindow(window);
> }
> }
>
> class Click extends MouseAdapter {
> @Override
> public void mouseClicked(MouseEvent e) {
> System.exit(0);
> }
>
> }
> }[/code]
>
> You should see the grey screen and text "Screen X" in the middle of the screen giving you the number of the device. If the problem persists you will see the grey rect and label only on one of the screens. If it works, both of your screens will be grey. To close it just click the mouse. If the pure java (above) works then the problem is likely related to mathlab (maybe references old JVM somewhere???), if not then posting your exact configuration (JVM version, OS version) would help.
>
> Cheers
> [Message sent by forum member 'rah003' (rah003)]
>
> http://forums.java.net/jive/thread.jspa?messageID=195390
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".