Tomas,

I agree. The real problem was just that you were trying to create the model
before defining the frame. This works fine:


  public static void main(String[] args) {
    new Test2(strXyzHOH);
  }

  public Test2(String model) {
    JFrame newFrame = new JFrame();
    newFrame.getContentPane().add(this);
    newFrame.setSize(300, 300);
    newFrame.setVisible(true);
    adapter = new SmarterJmolAdapter();
    viewer = JmolViewer.allocateViewer(this, adapter);
    viewer.loadInline(model);
  }


Bob


On Thu, Dec 10, 2009 at 9:33 PM, Tomas Pluskal <[email protected]> wrote:

> Dear Robert,
>
> Thank you for the reply. I understand that I can call
> viewer.loadInline() after the component is constructed... However, I
> don't like this :)
> I would like to design a component (JComponent), which takes a
> structure (as String) in a constructor parameter and shows the
> structure in 3D.
>
> JComponent threeDcomponent = new MyThreeDComponent(myStructure);
>
> In Swing, I think this is a common approach. For example:
>
> JComponent labelComponent = new JLabel(myText);
>
> or
>
> JComponent tableComponent = new JTable(myData, columnNames);
>
> However, with Jmol 11.8 designing such component is impossible.
> I will always have to write
>
> JComponent threeDcomponent = new MyThreeDComponent();
> ((MyThreeDComponent ) threeDcomponent).loadStructure(myStructure);
>
> So, even though this is not a huge problem, I believe it should be
> changed.
> Or is there any practical reason why model should not be created
> before the component is shown?
>
> Best,
>
> Tomas
>
>
>
> On Dec 11, 2009, at 11:50 AM, Robert Hanson wrote:
>
> > Tomas, you are absolutely correct. You are trying to create a model
> > before the frame is defined. That's just not possible, and if it was
> > in some distant past, it shouldn't have been. Here's (in my mind) a
> > more logical construction of events. In this way there is no model
> > during construction, and the repaint is not fired until after Test()
> > is initialized. There were some changes between 11.6 and 11.8 which
> > relate to this, but I would argue it's not a bug.
> >
> > package org.jmol;
> >
> > import java.awt.Dimension;
> > import java.awt.Graphics;
> > import java.awt.Rectangle;
> > import javax.swing.JFrame;
> > import javax.swing.JPanel;
> > import org.jmol.adapter.smarter.SmarterJmolAdapter;
> > import org.jmol.api.JmolAdapter;
> > import org.jmol.api.JmolViewer;
> >
> > public class Test extends JPanel {
> >
> >   // Main application
> >   public static void main(String[] args) {
> >     (new Test()).viewer.loadInline(strXyzHOH);
> >   }
> >
> >   public Test() {
> >     adapter = new SmarterJmolAdapter();
> >     viewer = JmolViewer.allocateViewer(this, adapter);
> >     JFrame newFrame = new JFrame();
> >     newFrame.getContentPane().add(this);
> >     newFrame.setSize(300, 300);
> >     newFrame.setVisible(true);
> >   }
> >
> >   private final static String strXyzHOH = "3\nwater\nO  0.0 0.0 0.0\n"
> >       + "H  0.76923955 -0.59357141 0.0\n" + "H -0.76923955
> > -0.59357141 0.0\n";
> >
> >   private JmolViewer viewer;
> >   private JmolAdapter adapter;
> >   private Dimension currentSize = new Dimension();
> >   private Rectangle rectClip = new Rectangle();
> >
> >   public void paint(Graphics g) {
> >     getSize(currentSize);
> >     g.getClipBounds(rectClip);
> >     viewer.renderScreenImage(g, currentSize, rectClip);
> >   }
> >
> > }
> >
> >
>
> ===============================================
> Tomas Pluskal
> G0 Cell Unit, Okinawa Institute of Science and Technology
> 12-22 Suzaki, Uruma-shi, Okinawa 904-2234, JAPAN
> TEL:  +81-98-921-3966
>
>
>
>
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> Jmol-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-developers
>



-- 
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to