Reputation: 880
The following code supposed to read a file containing a set of molecular structures, then add a bunch of JPanels (equal to the number of molecules) and create a molecule on each panel. I get the right no of panels at the runtime. However only the first molecule is drawn on the first panel?
Upvotes: 0
Views: 98
Reputation: 1247
Is ReadSDF working properly? Without knowing much more, it might be possible that fragments is not being initialised properly, so when you go to access the elements it doesn't work properly, an exception is thrown which is caught and ignored by something higher up.
Cory Larson's code seems like it should work to me. It is logically the same.
I notice where you override 'paintComponent' in MolViewer, you call super.paintComponents(g) (a method of Container) rather than paintComponent (the method of JComponent). I haven't done enough with graphics in swing, to know if this is correct though, so feel free to ignore this.
Also, a (very) small thing: You're using LinkedLists for random access. ArrayList would be a better implementation in general if you're accessing with an index number.
Upvotes: 0
Reputation: 107566
The drawMolViewPanel()
function seems a little overengineered. For one, the panes
list seems to be mostly temporary (you add objects to it, then from that list, add them to the MolTable
's own panel collection; I don't think you need it). If I understand the function correctly, this does the same thing and makes more sense to me:
public void drawMolViewPanel(String sdf) throws FileNotFoundException, CDKException
{
ReadSDF(sdf);
this.removeAll();
for (int i = 0; i < this.fragments.size(); i++)
{
MolViewer mv = new MolViewer();
mv.setMolecule((Molecule)this.fragments.get(i));
this.add(mv);
}
this.revalidate();
this.repaint();
}
I'm not entirely sure that's your issue, unfortunately.
Upvotes: 1