Using an external monitor with Java

A piece of code to create a full screen java frame without bar and unfocusable on a secondary screen.

It can be used to generate a power-point-like presenter.

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// find out which graphic devices are available
GraphicsDevice sd[] = ge.getScreenDevices();
for (GraphicsDevice d : sd) {
   // skip the main device 
   if (d.equals(ge.getDefaultScreenDevice())) continue;
   //get dimension and position of the external device
   Rectangle r = d.getDefaultConfiguration().getBounds();
   //create a new JFrame in the external device
   JFrame f = new JFrame(d.getDefaultConfiguration());
   // make the frame cover the whole external device
   f.setSize(r.width, r.height);
   // OPTIONAL - take out the bar from the window
   // OPTIONAL - make sure the external window cannot get the focus
   //create, paint and show a JPanel in the external window
   JPanel p=new JPanel();
   // show the frame on the external window
Posted in Java

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: