This example shows how to create the MViewPane JavaBean component and embed it in a Swing Container component.
By default, MViewPane has one single cell into which a molecule can be set by different ways:
Loaded from file or URL
Pasted or Dropped from other applications
Molecule object set directly via API
Molecule String representation set via API
This example demonstrates loading molecules from files by creating a File > Open menu.
This image is a snapshot of ViewSimple.java
in use. The major part of this code is shown below.
Creating and embedding the single-cell MViewPane component in the JPanel:
public class ViewSimple extends JPanel { public ViewSimple() { viewPane = new MViewPane(); setLayout(new BorderLayout()); add(viewPane, BorderLayout.CENTER); } }
Setting a java.io.File
to the single cell having the index 0 without format options:
viewPane.setM(0, fileChooser.getSelectedFile(), null);
In case a multi-molecule file is opened with this method, it is considered to be an animation, or molecular dynamics simulation, and the structures will be shown one after another.
However it is more common to have multi-molecule files containing molecules without such a relation. These molecules are typically shown in a table.
The View Table example shows how to create a table with multiple cells.