I tried it too but nothing! I even tried a JEditorPane... I really need to know it and i'll keep trying. If you find the solution please let me know.
Good luck!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's been a while since I last looked into the details of a JPanel, but in essence, the IE instance needs to attach itself to a windows instance pointed to by the hwnd variable. I don't know if it's possible with a JPanel. A heavyweight window is required, since a lightweight one doesn't have its own window instance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes its possible to embed canvas in JPanel and then use that canvas to host IECanvas. I have done the same and it works correctly. However Please note that since the canvas is a heavy weight component which is hosted in a light weight component, it will always be on top.
My two pence.
Prasad.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok one hack is to get the canvas to attach itself to a JFrame (IEBrowser), keep the JFrame invisible and then grab its contentpanel and add that to the JPanel
:)
canvas = new IECanvas(false);
canvas.addIEEventListener(this);
browser = new IEBrowser(urlString);
canvas.addIEEventListener(browser);
I have been working on a derivative of IECanvas, and I needed to fit my solution into an interface that returned a JComponent. I noticed some quirkiness with layout managers that can make this tricky.
I don't have exact code for you since I wasn't using IECanvas directly, but here is something to try:
IECanvas canvas = new IECanvas(false);
canvas.addIEEventListener(b);
JPanel pnl = new JPanel(new GridLayout(1, 1));
pnl.add(canvas);
One thing I noticed was that with the default layout manager, it never seemed to size itself correctly within the JPanel.
I really doubt that this will work in any application where you try to treat the JPanel as a lightweight component (like put it inside a JTabbedPane or something like that), you need to treat it like a heavyweight component even though it isn't one.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have done it and it works very fine exept for focus.
To fix a timing issue I made some changes in the package that I have sent to the author.
I did like this (could be improved i guess):
Hello, I know I'm not supposed to really embed IECanvas in a lightweight component, however, is it possible to embed the canvas in a JPanel?
When I try this, the canvas is created and I can interact with it in code, however, it is not visible on the JPanel. Any ideas? am I just plain nuts?
I tried it too but nothing! I even tried a JEditorPane... I really need to know it and i'll keep trying. If you find the solution please let me know.
Good luck!
It's been a while since I last looked into the details of a JPanel, but in essence, the IE instance needs to attach itself to a windows instance pointed to by the hwnd variable. I don't know if it's possible with a JPanel. A heavyweight window is required, since a lightweight one doesn't have its own window instance.
Hello,
Yes its possible to embed canvas in JPanel and then use that canvas to host IECanvas. I have done the same and it works correctly. However Please note that since the canvas is a heavy weight component which is hosted in a light weight component, it will always be on top.
My two pence.
Prasad.
What about a heavyweight component like java.awt.Panel...
public void addBrowserWindow(IECanvas w) {
canvas = w;
Panel pnl = new java.awt.Panel();
getContentPane().add(pnl, BorderLayout.CENTER);
getContentPane().add(w, BorderLayout.CENTER);
}
However what i need to do is to manage mouse events...
pnl.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("click x: " + evt.getPoint().x + " y: " + evt.getPoint().y);
}
});
i tried this but i got nothing, i know it will be on top that's why i can't get mouse position. Can you give me a hand?
Ok one hack is to get the canvas to attach itself to a JFrame (IEBrowser), keep the JFrame invisible and then grab its contentpanel and add that to the JPanel
:)
canvas = new IECanvas(false);
canvas.addIEEventListener(this);
browser = new IEBrowser(urlString);
canvas.addIEEventListener(browser);
browser.addBrowserWindow(canvas);
browser.setBounds(300, 300, 500, 300);
this.add(browser.getContentPane(), BorderLayout.CENTER);
----
Kevin
Thanx Kevin for the post, i'll try this out and let you know.
I tried what you said Kevin, but still it doesn't work. Any other ideas?
I have been working on a derivative of IECanvas, and I needed to fit my solution into an interface that returned a JComponent. I noticed some quirkiness with layout managers that can make this tricky.
I don't have exact code for you since I wasn't using IECanvas directly, but here is something to try:
IECanvas canvas = new IECanvas(false);
canvas.addIEEventListener(b);
JPanel pnl = new JPanel(new GridLayout(1, 1));
pnl.add(canvas);
One thing I noticed was that with the default layout manager, it never seemed to size itself correctly within the JPanel.
I really doubt that this will work in any application where you try to treat the JPanel as a lightweight component (like put it inside a JTabbedPane or something like that), you need to treat it like a heavyweight component even though it isn't one.
I have done it and it works very fine exept for focus.
To fix a timing issue I made some changes in the package that I have sent to the author.
I did like this (could be improved i guess):
package test;
import java.awt.*;
import javax.swing.*;
import nothome.mswindows.IECanvas;
import nothome.mswindows.IEEventListener;
import java.awt.event.*;
public class BrowserJPanel extends JPanel implements /*ActionListener,*/ IEEventListener
{
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 3038318532151369045L;
protected IECanvas m_IECanvas;
protected boolean m_ShowContextMenu=false;
public BrowserJPanel() {
BrowserJPanel me = this;
me.setLayout(new BoxLayout(me, BoxLayout.Y_AXIS));
//this.setBackground(Color.YELLOW);
/*urlField = new JTextField();
Dimension d = new Dimension(1,1);
JPanel upperPanel = new JPanel();
upperPanel.setLayout(new GridLayout());
upperPanel.add(urlField);
upperPanel.setPreferredSize(d);
upperPanel.setMaximumSize(d);
me.add(upperPanel);
*/
m_IECanvas = new IECanvas(false);
m_IECanvas.addIEEventListener(me);
me.add(m_IECanvas);
}
// We initialize the IECanvas on addNotify.
public void addNotify() {
super.addNotify();
}
// IEEventListener impl.
public void onStatusTextChange(String status) {
if(status.indexOf("WM_CLOSE")>=0){
onQuit();
}
else{
}
}
public void onTitleChange(String status) {
}
public void onDocumentComplete(String status) {
//urlField.setText("hghhh");
this.validate();
// this.validateTree();
}
public void onBeforeNavigate2(String url) {
System.out.println("java: OnBeforeNaviate2: " + url);
// urlField.setText(url);
}
public void onNavigateComplete2(String status) {
// statusLabel.setText(status);
}
public void onDownloadComplete() {
}
public void onProgressChange(int progress, int max) {
System.out.println("java: progress: " + progress + ", max: " + max);
}
public void onCommandStateChange(int command, boolean enabled) {
}
public void onQuit() {
System.out.println("onQuit()\n");
//navigateTo("about:blank");
m_IECanvas.removeIEEventListener(this);
//this.m_IECanvas.setURL("http://www.dn.se");
// System.exit(0);
}
public boolean showContextMenu() {
return m_ShowContextMenu;
}
public void navigateTo(String urlString)
{
m_IECanvas.setURL(urlString);
}
public static void main(String[] argv) {
// String urlString = "http://www.dn.se";
String urlString = "http://www.idg.se";
if(argv.length > 0)
urlString = argv[0];
JFrame f = new JFrame();
f.getContentPane().setLayout(new GridLayout(1,1,0,0));
f.setBackground(Color.GREEN);
f.setTitle("Mentice Embedded Browser");
JTabbedPane tabp = new JTabbedPane();
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
f.addWindowListener(l);
BrowserJPanel b = new BrowserJPanel();
BrowserJPanel b1 = new BrowserJPanel();
BrowserJPanel b2 = new BrowserJPanel();
// f.getContentPane().add(b);
// f.getContentPane().add(b1);
// f.getContentPane().add(b2);
tabp.addTab("b", b);
tabp.addTab("b1", b1);
tabp.addTab("b2", b2);
f.getContentPane().add(tabp);
f.setVisible(true);
f.setLocation(50,50);
f.setSize(500,500);
f.validate();
// b.navigateTo(urlString);
// b.validateTree();
try
{
Thread.sleep(50);
}
catch (InterruptedException e)
{
}
b.navigateTo(urlString);
b1.navigateTo("http://www.aftonbladet.se");
b2.navigateTo("http://www.expressen.se");
}
/* (non-Javadoc)
* @see nothome.mswindows.IEEventListener#oneParamCallBack(java.lang.String)
*/
public void oneParamCallBack(String param1)
{
// Keep this empty
}
/* (non-Javadoc)
* @see nothome.mswindows.IEEventListener#twoParamCallBack(java.lang.String, java.lang.String)
*/
public void twoParamCallBack(String param1, String param2)
{
// Keep this empty
}
}