Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4367577

JDialog and JPopupMenu are displayed in wrong monitor when using Multiple Displa

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.3.1
    • 1.3_01, 1.1.2, 1.3.0
    • client-libs
    • 1.3.1
    • generic, sparc
    • solaris_2.6, solaris_7, solaris_8



        Name: stC104175 Date: 08/31/2000


        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-beta)
        Java HotSpot(TM) Client VM (build 1.3-beta, mixed mode)


        /*
          JDialog and JPopupMenu are displayed in wrong monitor when using Multiple
        Display option of Graphic2D.

          All JDialogs and JPopupMenus initialized by a GUI displayed on a Monitor
        (Display) different than the default is always displayed in the default Display
        (DISPLAY=:0.0)

        Enclosed is a demo that will duplicate the problem.

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

        public class DualHeadTest extends JFrame implements ActionListener
        {
          private boolean isMain = false;

          private GraphicsConfiguration graphConf = null;

          private JButton popupButton = null;
          private JButton dialogButton = null;
          private JButton frameButton = null;
          private JButton okButton = null;

          private JFrame demoFrame = null;

          private JPopupMenu aPopup = null;
          private JMenuItem okMenuItem = null;

          private JMenu fileMenu = null;
          private JMenuItem exitMenuItem = null;


          private static Dimension screenSize = null;

          public DualHeadTest( String title, GraphicsConfiguration gc ,
                               boolean mainVwr )
          {
            super( title, gc );
            graphConf = gc;
            isMain = mainVwr;

            super.addWindowListener(new WindowAdapter()
              {
                public void windowClosing(WindowEvent e)
                {
                  shutdown();
                }
              });

            super.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

            exitMenuItem = new JMenuItem("Exit", 'x');
            exitMenuItem.addActionListener(this);
            exitMenuItem.setCursor( new Cursor(Cursor.HAND_CURSOR) );

            fileMenu = new JMenu("File");
            fileMenu.setMnemonic('F');
            fileMenu.add(exitMenuItem);

            JMenuBar menuBar = new JMenuBar();
            menuBar.add( fileMenu );

            super.setJMenuBar( menuBar );

            popupButton = makeButton( "Show JPopupMenu" );
            dialogButton = makeButton( "Show JDialog" );
            frameButton = makeButton( "Show JFrame" );
            okButton = makeButton( "OK" );

            okMenuItem = new JMenuItem( "Do Nothing ... is a Demo" );
            okMenuItem.addActionListener( this );

            aPopup = new JPopupMenu( "Menu for JPopupMenu" );
            aPopup.setInvoker( popupButton );
            aPopup.add( okMenuItem );

            Container contentPane = super.getContentPane();
            contentPane.setLayout( new BoxLayout( contentPane, BoxLayout.Y_AXIS ) );
            contentPane.add( Box.createVerticalStrut(8) );
            contentPane.add( popupButton );
            contentPane.add( Box.createVerticalStrut(8) );
            contentPane.add( dialogButton );
            contentPane.add( Box.createVerticalStrut(8) );
            contentPane.add( frameButton );
            contentPane.add( Box.createVerticalStrut(8) );

            super.pack();

            if( null == screenSize )
              screenSize = Toolkit.getDefaultToolkit().getScreenSize();

            Dimension size = super.getSize();
            
            int y = (screenSize.height - size.height) / 2 ;
            int x = (screenSize.width - size.width ) / 2 ;

            super.setLocation(x, y);
            super.setVisible( true );
            
          }

          public void actionPerformed(ActionEvent evt)
          {
            Object source = evt.getSource();
              
            if(source == popupButton )
              {
                aPopup.show( popupButton, 0,0 );
              }
            else if(source == dialogButton )
              {
                JOptionPane.showMessageDialog( this,
                                               "This is a Demo...",
                                               "DEMO",
                                               JOptionPane.INFORMATION_MESSAGE );
              }
            else if(source == frameButton )
              {
                demoFrame = new JFrame( "JFrame Demo", graphConf );

                Container demoContentPane = demoFrame.getContentPane();
                demoContentPane.setLayout( new BoxLayout( demoContentPane,
                                                          BoxLayout.Y_AXIS ) );
                demoContentPane.add( Box.createVerticalStrut(8) );
                demoContentPane.add( okButton );
                demoContentPane.add( Box.createVerticalStrut(8) );

                demoFrame.setSize(100, 100);
                
                Dimension size = demoFrame.getSize();
            
                int y = (screenSize.height - size.height) / 2 ;
                int x = (screenSize.width - size.width ) / 2 ;

                demoFrame.setLocation(x, y);
                demoFrame.setVisible( true );
                
              }
            else if(source == okButton )
              {
                demoFrame.setVisible(false);
                demoFrame.dispose();

                demoFrame = null;
              }
            else if(source == okMenuItem )
              {
                Toolkit.getDefaultToolkit().beep();
              }
            else if(source == exitMenuItem )
              {
                shutdown();
              }
          }
          
          private void shutdown()
          {
            super.setVisible( false );

            okMenuItem.removeActionListener(this);
            exitMenuItem.removeActionListener(this);
            popupButton.removeActionListener(this);
            dialogButton.removeActionListener(this);
            frameButton.removeActionListener(this);
            okButton.removeActionListener(this);

            super.dispose();

            if( isMain )
              {
                System.exit( 0 );
              }
          }


          private JButton makeButton( String txt )
          {
            JButton btn = new JButton( txt );
            btn.addActionListener( this );
            return btn;
          }
          

          public static void main(String[] args)
          {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice[] gs = ge.getScreenDevices();

        DualHeadTest[] viewers = new DualHeadTest[gs.length];

            for (int j = 0; j < gs.length; j++)
              {
                String title = "Viewer # " + Integer.toString(j);
                System.out.println("Creating " + title );
                viewers[j] = new DualHeadTest(title,
                                              gs[j].getDefaultConfiguration(),
                                              (0 == j) );
              }
          }

        }
        (Review ID: 106482)
        ======================================================================

              ibdsunw Ibd Ibd (Inactive)
              stompkinsunw Sean Tompkins (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: