Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Two Screens on one Computer (with Java)

Posted on 2000-04-03
Medium Priority
Last Modified: 2012-05-04
I'm looking for a library that gives me the possibility to access two Screens on a Windows (9x or NT) Machine. I'd need to create one Frame on one screen and the other on the other screen.

Okay, I know that technically it would be possible to do something with JNI and that the solution won't be pure Java. Please, what I'm looking for a library that does this or some lines of code I can copy and compile. I don't know anything of JNI or of the Win-API to implement this myself. I can even envision to *pay* someone to get this working. E-Mail me if you think you are able to do this. We'll discuss then further details.
Question by:MadMike
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2

Expert Comment

ID: 2680663
Are you trying to write two "screens" to show two frames on two seperate monitors? Or are you just attempting to display two Frames on one montor? If this is the first option, then you first need a dual monitor graphics card. When you have this installed, the dual monitor just acts like an extension to your primary monitor. That means that if your screen resolution both monitors is 800x600, then the first monitor has the bound <0,0>X<800,600> and the second has <800, 0>x<1600, 600>.

If the answer is the latter, then this is a very simple task to display to frames simultaneously. This shows how easy:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test{
  public static void main(String[] args) {            

  JFrame frame1 = new JFrame("Frame 1");
  JFrame frame2 = new JFrame("Frame 2");
  frame1.setBounds(0, 0, 200, 200);
  frame2.setBounds(200,0,200, 200);
  }//Close Main


If I'm still not understanding what you need, please describe it with a little more detail and I'd be happy to help.

Expert Comment

ID: 2680667
By the way, I'm always open for small contract jobs... I don't think you'll need to pay someone for this though.
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2680908
The JDK 1.3 includes 2D API changes for multiple monitor support. If you can use JDK 1.3 (now in release candidate 2), this looks like your solution. Here is a description of the new feature from the JDK release notes:

You can now render on multiple screens by creating Frame, JFrame, Window, or JWindow objects with the GraphicsConfiguration of the target GraphicsDevice.
The new Frame constructor, Frame(GraphicsConfiguration), enables creation of a Frame object on a different screen device.

The new Window constructor, Window(Window, GraphicsConfiguration), constructs a new invisible window with the specified window as its owner and the GraphicsConfiguration of a screen device.

The new GraphicsConfiguration getBounds method returns the bounds of the GraphicsConfiguration in device coordinates. If you have a virtual device, then the device coordinates returned from getBounds are virtual device coordinates.

Finally, the new Component getGraphicsConfiguration method returns the GraphicsConfiguration with which the Component was created.

In a virtual device configuration consisting of more than one physical screen device, the GraphicsConfiguration objects' coordinates are relative to the virtual coordinate system. For this reason, virtual coordinates must be used when calling the setLocation method of a Frame or Window. Similarly, calling getBounds of a GraphicsConfiguration in a virtual device environment returns virtual device coordinates.

The following code sample creates a JFrame object for each GraphicsConfiguration on each screen device in the GraphicsEnvironment. It offsets the coordinates of the intended location of the JFrame with the bounds of the GraphicsConfiguration to ensure that the JFrame appears on the screen of the specified GraphicsConfiguration.

        GraphicsEnvironment ge = GraphicsEnvironment.
        GraphicsDevice[] gs = ge.getScreenDevices();
        for (int j = 0; j < gs.length; j++) {
            GraphicsDevice gd = gs[j];
            GraphicsConfiguration[] gc = gd.getConfigurations();
            for (int i=0; i < gc.length; i++) {
                    JFrame f = new JFrame(gs[j].getDefaultConfiguration());
                    Canvas c = new Canvas(gc[i]);
                    Rectangle gcBounds = gc[i].getBounds();
                    int xoffs = gcBounds.x;
                    int yoffs = gcBounds.y;
                    f.setSize(300, 150);
                    f.setLocation((i*50)+xoffs, (i*60)+yoffs);
If the bounds of a GraphicsConfiguration is not taken into account in this sample, a JFrame would appear at location (i*50, i*60) on the primary screen, which might be different than the screen of the specified GraphicsConfiguration.
For more information on how the Java 2D API supports multi-screen environments, see Rendering in a Multi-Screen Environment in the Programmer's Guide to the Java 2D API.

Best regards,
Jim Cakalic
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 2681346
Good job, jim_cakalic. You'll get the points.

Just a last thing I'd really like to know before I close this Question as answered. Has anyone actually *used* two screens ('monitors' if you like that better, althought then you can confuse it with the term from the synchronization mechanism... ;) or was this "just" a research job you did?
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2681435
Sorry, no, I haven't used this capability. I've only been using JDK 1.3 for a month or so and haven't had the resources (time or hardware) to investigate this new functionality.

Jim Cakalic
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2681440
Because this was "just a research job", I'll understand if you choose to reduce the points for the answer :)


Author Comment

ID: 2681846
no.. i'll give you all 400 points, promised is promised. But I'll give a 'D' Grade afterwards...

   *evil-grin*   ;)
LVL 19

Accepted Solution

Jim Cakalic earned 1600 total points
ID: 2682289
Ouch -- there goes my GPA! Guess I won't make site valedictorian this year. Oh well ... maybe I still have a chance to win Mister Universe if I start taking those steroids today.

Author Comment

ID: 2685536

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question