views:

87

answers:

1

I have the following program to test GlassPane, but it doesn't work with JDIC's WebBrowser, does anyone know what I did wrong and how to make it work ?

import org.jdesktop.jdic.browser.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;

public class Test_Panel extends JPanel
{
  static WebBrowser webBrowser=new WebBrowser();
  static int W=802,H=702;

  Test_Panel()
  {
    setPreferredSize(new Dimension(W,H));
    setLayout(new BorderLayout());
    webBrowser.setPreferredSize(new Dimension(W,H));
//    add("Center",webBrowser);

    try { webBrowser.setURL(new URL("http://www.yahoo.com")); }
    catch (MalformedURLException e) { e.printStackTrace(); }
  }

  static void Create_And_Show_GUI() 
  {
    JFrame frame=new JFrame("Test");
    frame.add(new Test_Panel());
    frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e)  { System.exit(0); } });

    new My_GlassPane(frame,W,H);

    frame.pack();
    frame.setBounds(0,0,W,H);
    frame.setVisible(true);
  }

  public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Create_And_Show_GUI(); } }); }
}

class My_GlassPane extends JComponent
{
  JFrame f;
  int W,H,Edge,Size;

  public My_GlassPane(JFrame f,int W,int H)
  {
    this.f=f;
    this.W=W;
    this.H=H;
    Edge=W/100;
    Size=W/5;
    f.setGlassPane(this);
    f.getGlassPane().setVisible(true);
  }

  public void paint(Graphics g)
  {
    g.setColor(Color.blue);
    g.fillOval(W/6,H*18/120,W*2/3,H*2/3);
    g.setColor(Color.white);
    g.setFont(new Font("Times New Roman",0,Size));
    g.drawString("Test",W/3,H*68/120);
  }
}

If you uncomment "add("Center",webBrowser);" you will see what I mean, the glasspane won't show up, why ?

You need to have "jdic.jar" and "IeEmbed.exe" to make it work, the version I have is 0.9.1.0 and you can get them here : https://jdic.dev.java.net/servlets/ProjectDocumentList?folderID=3606&expandFolder=3606&folderID=5497

Frank

+2  A: 

As I've read, WebBrowser is an AWT component while GlassPane is a Swing component. There is a common problem mixing heavyweight and lightweight components. I don't think there is a workaround on what you're trying to do.

More information on this subject can be found in this discussion.

Alex