ChemAxon fa971619eb
27-07-2009 16:55:58
I'm trying to use a MViewPane and set a molecule to it and immediatly open the sketcher to allow it to be edited. I see the methods that should do this, but its not working correctly.
I create the MView pane like this
mvp = new MViewPane();
mvp.setDetachable(true);
mvp.setEditable(MViewPane.SKETCHABLE);
and then I try to set mol and open sketcher like this:
mvp.setM(0, "c1ccccc1");
mvp.openSketcher(0);
The sketcher opens, but it does not contain the structure I just set. When I close the sketcher without doing anything the structure appears.
Any suggestions for how to get this to work?
Thanks
Tim
ChemAxon 7c2d26e5cf
28-07-2009 08:52:33
I have written a small standalone example (based on your code). In this example, auto displaying sketcher works for me.
ChemAxon fa971619eb
28-07-2009 09:10:45
Thanks.
Your example works, my virtually ideantical one doesn't.
The difference is that I was calling the openSketcher method from the EDT. If you modify your example as follows you get the behaviour I saw.
Tim
public static void main(String[] args) {
final MViewPane mvp = new MViewPane();
mvp.setDetachable(true);
mvp.setEditable(MViewPane.SKETCHABLE);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mvp);
frame.pack();
frame.setVisible(true);
Runnable r = new Runnable() {
public void run() {
mvp.setM(0, "c1ccccc1");
mvp.openSketcher(0);
}
};
SwingUtilities.invokeLater(r);
}
ChemAxon 7c2d26e5cf
28-07-2009 09:24:57
The problem is that you places the setM() calling inside the run method that is performed on the EDT thread. If you call setM() on the main thread, the structure displays in the sketcher:
frame.setVisible(true);
mvp.setM(0,"c1ccccc1");
Runnable r = new Runnable() {
public void run() {
mvp.openSketcher(0);
}
};
SwingUtilities.invokeLater(r);