Using JGoView with JPanel

Hi,
Has anyone tried using JGoView and JGoViewPalette with JPanel instead of JFrame. i have a requirement to use this as a component inside the application which uses JPanel

Rgds,
San

That should be fine–what’s the problem you encounter?

Hi,
This is my code for JApplet. This seems to be not working - specifically the drag and drop from JGoPalette to JGoView. Can you find the reason?

package mypackage2; import javax.swing.JApplet; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.JSplitPane; import java.awt.Rectangle; import com.nwoods.jgo.JGoPalette; import com.nwoods.jgo.JGoView;

public class Applet4 extends JApplet
{

private BorderLayout borderLayout1 = new BorderLayout();
private JSplitPane jSplitPane1 = new JSplitPane();
private JGoPalette jGoPalette1 = new JGoPalette();
private JGoView jGoView1 = new JGoView();

public Applet4()
{
}

public void init()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}

}

public static void main(String[] args)
{
Applet4 applet = new Applet4();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet, BorderLayout.CENTER);
frame.setTitle(“Applet Frame”);
applet.init();
applet.start();
frame.setSize(300, 300);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
frame.setLocation((d.width - frameSize.width) / 2, (d.height - frameSize.height) / 2);
frame.setVisible(true);
}

private void jbInit() throws Exception
{
this.getContentPane().setLayout(borderLayout1);
jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
jGoPalette1.setShowSampleItems(true);
jSplitPane1.add(jGoPalette1, JSplitPane.BOTTOM);
jSplitPane1.add(jGoView1, JSplitPane.TOP);
this.getContentPane().add(jSplitPane1, BorderLayout.CENTER);
}

static
{
try
{
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClass Name());
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFe elClassName());
}
catch(Exception e)
{
}

}
}

Santhosh

You need to call JGoView.initializeDragDropHandling().
If you might be running on a JRE of 1.3 or earlier, you’ll need to call that method from a different thread after the applet has been started, as you can find documented in the Java Developer Connection bug 4225247 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4225247).
Most of the example apps are written to run both as stand-alone applications as well as applets, so you can do the same thing–implement Runnable and override start():
public void start() { // Applet starting
new Thread(this).start(); // enable drag-and-drop from separate thread (JDC bug 4225247)
}
public void run() {
myView.initializeDragDropHandling();
}

But the Autoscroll is not working.

It works for me – could you give more information about what you are doing?