MarvinSketch3d window disappears behind MarvinSketchPane

User a200fcbc5e

17-02-2012 13:17:47

Hi,


I'm trying to add the MSketchPane to our app, but having problems with the MarvinView3d menu option.


It's not easy to replicate this behaviour in a small toy program as the JDialog in our app has quite a complex class hierarchy.


However, I've seen very similar behaviour in one of the Java examples on your website:


https://www.chemaxon.com/marvin/examples/beans/sketch-simple/SketchSimple.java.html


I'm hoping that if the example can be fixed, then that will sort out my problem.


So on with the example. (I'm running it exactly as on the page using java 1.6, except had to change the EXIT_ON_CLOSE constants to WindowConstants.DISPOSE_ON_CLOSE to make the compiler happy.)


 


Example Scenario 


===============


1. run the example


2.The frame with the "modal" check-box etc. appears. Re-size it so it's the same size or larger than the MSketchPane which will appear when you click  the "MarvinSketchDialog" button


3. Check the "modal" check-box.


4. Click  the "MarvinSketchDialog" button. MSketchPane appears.


5.  Select View -> Open MarvinView 3D menu option. MarvinView3d window opens briefly, then disappears behind both the MSketchPane and the other frame. I would expect the MarvinView 3d window to remain in front of the MSketchPane till you close it.


In my app, the equivalent of the frame in the example is unable to be moved while the MSketchPane is open, because I'm using the MSketchPane as modal. Therefore, when the MarvinView3d window disappears behind it, I have to close the whole app to be able to see the window again.


Thanks,


Barry


 


 


 


 

ChemAxon 7c2d26e5cf

20-02-2012 12:24:27

Insert MSketchPane into JDialog like this:


JDialog dialog = new JDialog(this, ModalityType.DOCUMENT_MODAL);
...
dialog.getContentPane().add(new MSketchPane());

Although the created JDialog is modal but it does not block the focus for child windows. You can read more about in in the javadoc:


http://docs.oracle.com/javase/6/docs/api/java/awt/Dialog.ModalityType.html#DOCUMENT_MODAL

User a200fcbc5e

20-02-2012 13:03:39

Sorry, I gave the wrong url.


This is the example code I was referring to.


https://www.chemaxon.com/marvin/examples/beans/dialog/DialogLauncher.java.txt


I understand that if the MSketchPane is set to modal, you can still input to children e.g MarvinView3d window.


If you follow the scenario (now that I've put the correct url) , it shows the problem - namely that when the MarvinView3d option is selected, the Marvinview3d window shows briefly and then disappears behing the Msketchpane and the frame with the buttons/checkbox.


Shouldn't the MarvinView3d display in front of the MSketchPane? 


Also, in my example if you instead leave the checkbox unchecked, and display the MSketchPane. This time the MarvinView3d window appears fine. But if you then click in the MsketchPane area, the MarvinView3d window disappears again behind both the MSketchpane and the button/checkbox window.

ChemAxon 5433b8e56b

21-02-2012 20:51:26

Hi,


consider what Tamás suggested, if you place the following line into the DialogLauncher code after the 61st line, then it is working as you would like it to work.


dialog.setModalityType(ModalityType.DOCUMENT_MODAL);

Regards,
Istvan


/*
 * Copyright (c) 1998-2011 ChemAxon Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * ChemAxon. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with ChemAxon.
 *
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import chemaxon.struc.*;
import chemaxon.formats.*;
import chemaxon.marvin.beans.*;

/**
 * Dialog launcher.
 * @version 4.0.2, 10/08/2005
 * @since   Marvin 2.6, 09/14/2000
 * @author Peter Csizmadia
 * @author Tamas Vertse
 */
public class DialogLauncher extends JFrame
    implements WindowListener, ActionListener
{
    /** The MarvinSketch and MarvinView dialogs are modal if true. */
    private boolean modalDialogs;

    public DialogLauncher() {
        setTitle("Marvin Dialog Launcher");
        addWindowListener(this);
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridLayout(4, 1));
    JCheckBox cb;
    JButton b;
    contentPane.add(b = new JButton("MarvinSketch Dialog"));
    b.addActionListener(this);
    b.setActionCommand("sketch");
    contentPane.add(b = new JButton("MarvinView Dialog"));
    b.addActionListener(this);
    b.setActionCommand("view");
    contentPane.add(cb = new JCheckBox("Modal"));
    cb.addActionListener(this);
    cb.setActionCommand("modal");
    contentPane.add(b = new JButton("Exit"));
    b.addActionListener(this);
    b.setActionCommand("exit");
    }

    /** Menu action performed. */
    public void actionPerformed(ActionEvent ev) {
        Object src = ev.getSource();
    String cmd = ev.getActionCommand();
        if(cmd.equals("modal")) {
        modalDialogs = ((JCheckBox)src).isSelected();
    } else if(cmd.equals("sketch")) {
        JDialog dialog = new JDialog(this, "MarvinSketch Dialog",
                     modalDialogs);
        MSketchPane sketcher = new MSketchPane();
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        // Keyboard events are received by the dialog window but
        dialog.addKeyListener(sketcher); // processed by the bean
        dialog.getContentPane().add(sketcher);
        dialog.pack();
        dialog.setVisible(true);
    } else if(cmd.equals("view")) {
        JDialog dialog = new JDialog(this, "MarvinView Dialog",
                     modalDialogs);
        MViewPane viewer = new MViewPane();
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        try {
        MolImporter mi = new MolImporter("caffeine.mol");
        Molecule mol = mi.read();
        viewer.setM(0, mol);
        } catch(Exception ex) {
        ex.printStackTrace();
        }
        // Keyboard events are received by the dialog window but
        dialog.addKeyListener(viewer); // processed by the bean
        dialog.getContentPane().add(viewer);
        dialog.pack();
        dialog.setVisible(true);
    } else if(cmd.equals("exit")) {
        System.exit(0);
    }
    }

    /** Does nothing */
    public void windowOpened(WindowEvent ev) { }

    /** Does nothing */
    public void windowClosed(WindowEvent ev) { }

    /** Closes the window. */
    public void windowClosing(WindowEvent ev) {
    System.exit(0);
    }

    /** Does nothing */
    public void windowIconified(WindowEvent ev) { }

    /** Does nothing */
    public void windowDeiconified(WindowEvent ev) { }

    /** Does nothing */
    public void windowActivated(WindowEvent ev) { }

    /** Does nothing */
    public void windowDeactivated(WindowEvent ev) { }

    public static void main(String[] args) {
    final JFrame w = new DialogLauncher();

    // pack and show the window in the Swing thread to avoid deadlocks
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
        w.pack();
        w.setVisible(true);
        }
    });
    }
}

User a200fcbc5e

22-02-2012 10:12:04

Thanks,


that solves the problem of the marvinview 3d window disappearing almost immediately.


However, now when you have the marvinview 3d window open infront of the MSketchPane, if you click on the MSketchPane, the marvinview3d window disappears behind both the MSketchPane and the other window. (To see this, you have to resize that window so it's directly behind the MsketchPane and MarvinView3d windows.)


(This happens whether the checkbox is checked or not.)


Is there any way to ensure the MarvinView3d window stays in front of the MSketchPane even when the MSketchPane is clicked on?

ChemAxon 5433b8e56b

02-03-2012 13:04:36

Hi Barry,


finally i could track down this issue, it seems it is a bug in the display of that MarvinView dialog, it does not have its parent component set properly, this is the root cause of the misbehaviour you are facing with.


I have filed a bug report to our issue tracker, how important is this fix for you?


Regards,
Istvan

User a200fcbc5e

05-03-2012 14:09:27

Thanks for filing the bug report.


Please note that Marvin2d and MarvinSpace also have the same issue, if you want to add that info to the bug report.


The fix is of medium priority for us.


I'm currently using the MSketchPane in the creation of a prototype, as an enhancement to our main application. It's not being used in our latest release.

ChemAxon 5433b8e56b

05-03-2012 15:14:49

All right,


then we try to include this in the 5.10 release, we will notify you in this forum, after the fix is ready.


Regards,
Istvan

ChemAxon 5433b8e56b

11-05-2012 15:01:08

Hi Barry,


I am happy to inform you that the fix is in the 5.10 release branch, so 5.10 release will contain the fix.


Regards,
Istvan