Skip to main content

Problem using WebBrowser

15 replies [Last post]
funkyidol
Offline
Joined: 2006-06-19
Points: 0

Im creating a java application that requires to have a embedded web browser. i tried using JDIC web browser but i donot see any webpage.
also i am unable to use the demo that is provided on JDIC website. just like my application the demo window does not shows any web page.
Im using windows XP, Zone alarm, Firefox 1.5

ps. i tried turning off my firewall but didnt helped??

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpfurtado
Offline
Joined: 2004-12-17
Points: 0

If you had not setted to layout manager to the BorderLayout and yet added a component using the BorderLayout constants (like PAGE_START, CENTER, SOUTH, etc) so that was indeed the problem.

> Also i want to change the frame title according to webpage like in any normal web-browser. how do i go about that??

Try using the WebBrowserListener (https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/...)

You can set the title of a JFrame receiving the event 'documentCompleted' of this listener.

funkyidol
Offline
Joined: 2006-06-19
Points: 0

I have been getting this error everytime i close my application.

IeEmbed.exe - Application Error
The instruction "0x7470b439" refrenced memory at "0x7470b439". the memory could not "read".
Click OK to ermiante the program

what could be the problem
I use netbeans5.0 to compile my app

Message was edited by: funkyidol

michael_shan
Offline
Joined: 2005-05-29
Points: 0

Hi,

How did you create your webbrowser? Have you set the autoDispose parameter to true?

funkyidol
Offline
Joined: 2006-06-19
Points: 0

I tried setting the defaultCloseOpertaion as "dispose" but it gives the following error:

Exception in thread "Thread-4" java.lang.NullPointerException: null pData
at sun.awt.windows.WComponentPeer.hide(Native Method)
at java.awt.Component.removeNotify(Component.java:5979)
at org.jdesktop.jdic.browser.WebBrowser.access$201(Unknown Source)
at org.jdesktop.jdic.browser.WebBrowser$2.run(Unknown Source)

I simply added the WebBrowser component (JDIC) in a Jpanle. as of now this is it. all the functionalities still need to be added.

michael_shan
Offline
Joined: 2005-05-29
Points: 0

Hi ,

Try set defaultClose to "JFrame.EXIT_ON_CLOSE". If still can't work , you'd better post your sample codes here for us to reproduce it.

thanks,
Michael

funkyidol
Offline
Joined: 2006-06-19
Points: 0

The application error post i had posted earlier was with EXIT_ON_CLOSE as the defualt close operation. im giving it again:

IeEmbed.exe - Application Error
The instruction "0x7470b439" refrenced memory at "0x7470b439". the memory could not "read".
Click OK to ermiante the program

Im providing my code as requested. following code is just the staring of the project and does not contains any functionality as such

/*
* MainWindow.java
*
* Created on June 16, 2006, 3:55 PM
*/

package Window;

import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.UIManager;
import org.jdesktop.jdic.browser.*;

/**
*
* @author Funkyidol
*/
public class MainWindow extends javax.swing.JFrame
{
WebBrowser webBrowser;
/** Creates new form MainWindow */
public MainWindow()
{
initComponents();
DefaultComboBoxModel model = new DefaultComboBoxModel();
addressBar.setModel(model);
try
{
test();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//
private void initComponents()
{
mainToolBar = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
browserBar = new javax.swing.JToolBar();
btBack = new javax.swing.JButton();
btNext = new javax.swing.JButton();
btStop = new javax.swing.JButton();
btRefresh = new javax.swing.JButton();
addressBar = new javax.swing.JComboBox();
btGo = new javax.swing.JButton();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel2 = new javax.swing.JPanel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
jMenu5 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
mainToolBar.setRollover(true);
jButton1.setText("Save");
mainToolBar.add(jButton1);

jPanel1.setAutoscrolls(true);
jPanel1.setMinimumSize(new java.awt.Dimension(800, 600));
jPanel1.setPreferredSize(new java.awt.Dimension(1024, 768));
browserBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
browserBar.setFloatable(false);
browserBar.setRollover(true);
btBack.setText("Back");
browserBar.add(btBack);

btNext.setText("Next");
browserBar.add(btNext);

btStop.setText("Stop");
browserBar.add(btStop);

btRefresh.setText("Refresh");
browserBar.add(btRefresh);

addressBar.setEditable(true);
addressBar.setMaximumRowCount(20);
addressBar.addKeyListener(new java.awt.event.KeyAdapter()
{
public void keyPressed(java.awt.event.KeyEvent evt)
{
addressBarKeyPressed(evt);
}
});

browserBar.add(addressBar);

btGo.setText("GO");
btGo.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent evt)
{
btGoMouseClicked(evt);
}
});

browserBar.add(btGo);

jPanel2.setLayout(new java.awt.BorderLayout());

jPanel2.setAutoscrolls(true);
jTabbedPane1.addTab("Untitled Page", jPanel2);

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(browserBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(browserBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE))
);

jMenu1.setText("File");
jMenuItem1.setText("Item");
jMenu1.add(jMenuItem1);

jMenuItem2.setText("Item");
jMenu1.add(jMenuItem2);

jCheckBoxMenuItem1.setText("CheckBox");
jMenu1.add(jCheckBoxMenuItem1);

jMenuBar1.add(jMenu1);

jMenu3.setText("Edit");
jMenuBar1.add(jMenu3);

jMenu4.setText("Veiw");
jMenuBar1.add(jMenu4);

jMenu5.setText("Tools");
jMenuBar1.add(jMenu5);

setJMenuBar(jMenuBar1);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(mainToolBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
.addContainerGap())
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(mainToolBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(577, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(23, 23, 23)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 577, Short.MAX_VALUE))
);
pack();
}//

private void addressBarKeyPressed(java.awt.event.KeyEvent evt)
{
if(evt.KEY_TYPED == evt.VK_ENTER)
{
javax.swing.JOptionPane.showMessageDialog(null,"yuhu");
AddressBarControl();
}
}

private void btGoMouseClicked(java.awt.event.MouseEvent evt)
{
AddressBarControl();
}

void AddressBarControl()
{
String address= addressBar.getSelectedItem().toString();
DefaultComboBoxModel model = new DefaultComboBoxModel();
model=(DefaultComboBoxModel) addressBar.getModel();
model.addElement(address);
model=InvertComboBoxModel(model);
addressBar.setModel(model);
addressBar.setSelectedIndex(0);
javax.swing.JOptionPane.showMessageDialog(null,address);
}

DefaultComboBoxModel InvertComboBoxModel(DefaultComboBoxModel model)
{
DefaultComboBoxModel temp= new DefaultComboBoxModel();
for(int i=model.getSize(),j=0; i>0 ;i--)
{
temp.insertElementAt(model.getElementAt(i-1),j++);
}
return temp;
}

void test() throws Exception
{

WebBrowser webBrowser = new WebBrowser(new URL("https://jdic.dev.java.net/#demos"));
// WebBrowser webBrowser = new WebBrowser(
new URL("file://E:/WORK/sm/studymaterial/javastuff/WebClientProgInJava/113.html"));
this.jPanel2.add(webBrowser,BorderLayout.CENTER);
//this.setTitle(webBrowser.getURL().toString());

}

public static void main(String args[])
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{

}
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new MainWindow().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JComboBox addressBar;
private javax.swing.JToolBar browserBar;
private javax.swing.JButton btBack;
private javax.swing.JButton btGo;
private javax.swing.JButton btNext;
private javax.swing.JButton btRefresh;
private javax.swing.JButton btStop;
private javax.swing.JButton jButton1;
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JToolBar mainToolBar;
// End of variables declaration

}

Im using Netbeans 5.0 to compile and run this code

michael_shan
Offline
Joined: 2005-05-29
Points: 0

I ran well with your sample code.

I've thought it's related with java version, but after changing to jdk1.4.2, it also worked well.

It seems related with your os system or some environments.

BTW, you can :
- try latest java version(if you're using jdk1.4.2)
- search for the error.

I'll go on trying to figure it out. Any progress I'll post here.

thanks,
Michael

funkyidol
Offline
Joined: 2006-06-19
Points: 0

Hi,
thnx for taking the pains.
im using the latest version JDK 1.5.0_6
i dont wht could be the error since the error message refers to a memory register value.
as u might have also seen there arnt any syntactical or any visible logical errors.
ill try to run my code on some other machine just to make sure.
will post the results soon.
thankyou

michael_shan
Offline
Joined: 2005-05-29
Points: 0

Hi,
As the post http://forums.java.net/jive/thread.jspa?messageID=125962 said, try this

frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
[b]frame.dispose();[/b]
System.exit(0);
}
});

hope it can work to you.

funkyidol
Offline
Joined: 2006-06-19
Points: 0

Thanks to every one
the error message has gone.
Maybe proper disposal was the issue.

stophi
Offline
Joined: 2006-12-21
Points: 0

The bug is still existing.
I couldn't use the workaround, because I am running the web browser in a JDialog and it is not a good idea to dispose the frame. But I resolved the problem by adding this to my dialog:

[code]
@Override
public void dispose() {
this.browser.setVisible(false); // browser is instance of org.jdesktop.jdic.browser.WebBrowser
super.dispose();
}
[/code]

Using jdic 0.9.4 cross-platform, jdk 1.6.0_03
Error occured on windows platform.

Maybe it is useful to someone.

Message was edited by: stophi

Message was edited by: stophi

tdanecito
Offline
Joined: 2005-10-10
Points: 0

I am having the same issue but while running in a JInternalFrame. If I have two JInternalFrames one with the Web Browser and the other without and the one with webbrowser is under the one (Z-Order) without the a webbrowser and I bring to the front the JInternalFrame by selecting it I get the jre error described previously.
I am using 0.9.4 of jdic and I have an older version 0.9.2 that never had this problem. I remember looking at this back in 2007 and thought it was a threading issue where an addNotify() is called but no removeNotify() or if it was it was done in a thread for some reason.

I will try this solution to see if it fixes the problem so I can update to the latest version of JDIC.

Thx,
-Tony

bpfurtado
Offline
Joined: 2004-12-17
Points: 0

A quick test would be to set IE as your default Web Browser (just for this test ;)).

I'll put the menu path to acomplish that here because it's not that intuitive.

IE >> Menu Tools >> Menu Item Options >> Tab Programs >> Mark the last checkbox

funkyidol
Offline
Joined: 2006-06-19
Points: 0

It doest matter what is the default browser since my application has started working.
I think it was the border layout property that was missing because that was the only change i made and it started woking.

Is it possible it happens that way??

Also i want to change the frame title according to webpage like in any normal web-browser. how do i go about that??

michael_shan
Offline
Joined: 2005-05-29
Points: 0

> Im creating a java application that requires to have
> a embedded web browser. i tried using JDIC web
> browser but i donot see any webpage.
> also i am unable to use the demo that is provided on
> JDIC website. just like my application the demo
> window does not shows any web page.
> Im using windows XP, Zone alarm, Firefox 1.5
Hi,
sorry to say that Firefox is not supported by JDIC now. It only supports IE and Mozilla. Refer https://jdic.dev.java.net/documentation/faq.html#How%20to%20choose%20IE%...? to know how to choose/config them.

Thanks,
Michael
> ps. i tried turning off my firewall but didnt helped??