Member Avatar for hfx642

This it only for people who are running a DUAL Monitor system.

I wrote a sample program to display what occurs.

No matter which button I click on (Primary Display OR Secondary Display),
the JOptionPane will pop up on the Primary Display.

What I would like to happen is...
If I click on the button on the Primary Display, pop up JOptionPane on the Primary Display.
If I click on the button on the Secondary Display, pop up the JOptionPane on the Secondary Display (instead of the Primary Display).

1. How can I get the JOptionPane to pop up on the Secondary Display, when initiated from the JButton on the Secondary Display?
(AND keep the JOptionPane pop up on the Primary Display when initiated from the JButton on the Primary Display!)
OR
2. Do I have to create a JDialog to mimic the JOptionPane to pop up on the Secondary Display?

//*****************************************************************************
//
// Dual_Test.java
//
// Application for Testing Dual Monitor System.
// I modified some of this code that I grabbed off of the web.
//
// 2011/12 - JJR
//
//*****************************************************************************

// Import Java Packages
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

//*****************************************************************************
// Dual_Test Class

public class Dual_Test extends JFrame
{

//=============================================================================
// Dual_Test Constructor

   public Dual_Test () {super ("Dual_Test Class"); Test_Proc ();}

//-----------------------------------------------------------------------------
// main Method

   public static void main (String args[])
   {
      Dual_Test App = new Dual_Test ();
      App.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
   }  // End of main Method

//*****************************************************************************

   public void Test_Proc ()
   {
      Rectangle virtualBounds = new Rectangle();
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] gs = ge.getScreenDevices();
      JFrame frame[][] = new JFrame[gs.length][];
      JButton Test_Bttns [] = new JButton [gs.length];

      for (int j = 0; j < gs.length; j++)
      {
         GraphicsDevice gd = gs[j];
//         System.out.println("");
//         System.out.println("Device " + j + ": " + gd);
         GraphicsConfiguration[] gc = gd.getConfigurations();
         frame[j] = new JFrame[gc.length];

         for (int i=0; i < gc.length; i++)
         {
//            System.out.println("  Configuration " + i + ": " + gc[i]);
//            System.out.println("    Bounds: " + gc[i].getBounds());
            virtualBounds = virtualBounds.union(gc[i].getBounds());
            frame[j][i] = new JFrame("Device: " + j, gc[i]);
            frame[j][i].setBounds(50, 50, 800, 600);
            frame[j][i].setLocation((int)gc[i].getBounds().getX() + 50,(int)gc[i].getBounds().getY() + 50);
//            frame[j][i].getContentPane().add(new JTextArea("Config:\n" + gc[i]));

            Test_Bttns [j] = new JButton ("Button: " + j);
            final int j_F = j;
            Test_Bttns [j].addActionListener (new ActionListener ()
            {
               public void actionPerformed (ActionEvent AE)
               {
                  JOptionPane.showMessageDialog (null
                  , "Test Message #" + j_F
                  , "Message Title #" + j_F
                  , JOptionPane.INFORMATION_MESSAGE);
               }
            });
            frame[j][i].getContentPane().add (Test_Bttns [j]);

            frame[j][i].setVisible(true);
         }
      }
//      System.out.println("");
//      System.out.println("Overall bounds: " + virtualBounds);
   }  // End of Test_Proc Method

//=============================================================================

}  // End of Dual_Test Class

Recommended Answers

All 2 Replies

1) that was (I'm sure that closed) bug about JPopupMenu


2) add parent is always safiest way how to do ... whatever

JOptionPane.showMessageDialog (myParent
, "Test Message #" + j_F
, "Message Title #" + j_F
, JOptionPane.INFORMATION_MESSAGE);

otherwise is JOptionPane dispayed on 1st. device to the CENTER location


3) some profesional GPU have got 2cores GPU, then GraphicsConfiguration[] for two GPUs in SLI mode returns 4 devices

Member Avatar for hfx642

Option #2 is exactly what I was looking for.
So simple. Thank-You mKorbel!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.