FaqMultipleMonitors

I have multiple monitors, why are context menus displayed on the wrong screen?

It should work but...

Multiple-monitor support relies on the correct implementation of the respective AWT APIs (GraphicsEnvironment, GraphicsDevice, GraphicsConfiguration). Compile and run this test program on your machine. The program should display one or several JFrames on each monitor. If all frames are placed on the first monitor, then you're out of luck. In such a case file bugs against JDK with as much details as possible about your graphics card and driver.

If the test program works but NetBeans doesn't work, then try starting Netbeans with the option

-J-Dnetbeans.popup.no_hack=true

and file a bug against NetBeans if it helps.

See also http://netbeans.org/bugzilla/buglist.cgi?keywords=DUAL_MONITOR


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

public class MultiMonitors
{
    public static void main(String[] argv) {
        GraphicsEnvironment ge =
           GraphicsEnvironment.getLocalGraphicsEnvironment();
        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(gd.getDefaultConfiguration());
               GCCanvas c = new GCCanvas(gc[i]);
               Rectangle gcBounds = gc[i].getBounds();
               int xoffs = gcBounds.x;
               int yoffs = gcBounds.y;
               f.getContentPane().add(c);
               f.setTitle("Screen# "+Integer.toString(j)+", GC# "+Integer.toString(i));
               f.setSize(300, 150);
               f.setLocation((i*50)+xoffs, (i*60)+yoffs);
               f.show();
             }
        }
    }

    static class GCCanvas extends Canvas
    {

        GraphicsConfiguration gc;
        Rectangle bounds;

        public GCCanvas(GraphicsConfiguration gc) {
            super(gc);
            this.gc = gc;
            bounds = gc.getBounds();
        }

        public Dimension getPreferredSize() {
            return new Dimension(300, 150);
        }

        public void paint(Graphics g) {
            g.setColor(Color.red);
            g.fillRect(0, 0, 100, 150);
            g.setColor(Color.green);
            g.fillRect(100, 0, 100, 150);
            g.setColor(Color.blue);
            g.fillRect(200, 0, 100, 150);
            g.setColor(Color.black);
            g.drawString("ScreenSize="+
                         Integer.toString(bounds.width)+
                         "X"+ Integer.toString(bounds.height), 10, 15);
            g.drawString(gc.toString(), 10, 30);
        }
    }
}

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo