tags:

views:

32

answers:

3

I wanted to embed brower into Frame.I wrote

public class MyBrowser{ 

   public static void main(String[] args) 
   { 
       final Display display = Display.getDefault(); 

       Frame frm = new Frame("MyBrowser"); 
       Canvas embedded = new Canvas(); 
       frm.add(embedded, BorderLayout.CENTER); 

       frm.pack(); 

       final Shell composite = SWT_AWT.new_Shell(display, embedded); 
       composite.setLayout(new FillLayout(SWT.VERTICAL)); 
       final Browser browser = installBrowser(composite, "http://www.baidu.com"); 
       frm.addWindowListener(new WindowAdapter() 
       { 
           public void windowClosing(WindowEvent e) 
           { 
           e.getWindow().dispose(); 
           //composite.dispose(); 
//            display.dispose(); 
           } 
       }); 

       JTextField addr = new JTextField(80); 
       addr.addActionListener(new ActionListener() 
       { 
           public void actionPerformed(final ActionEvent e) 
           { 
               display.syncExec(new Runnable() 
               { 
                   public void run() 
                   { 
                       browser.setUrl(((JTextComponent) e.getSource()).getText()); 
                   } 
               }); 
           } 
       }); 
       frm.add(addr, BorderLayout.NORTH); 

       frm.setSize(800, 600); 
       frm.setVisible(true); 
       while (frm.isDisplayable()) 
           if (!display.readAndDispatch()) 
               display.sleep(); 
//       display.dispose(); 
   } 

   public static Browser installBrowser(Composite parent, String homeURL) 
   { 
       Browser browser = new Browser(parent, SWT.EMBEDDED); 
       browser.setUrl(homeURL); 
       return browser; 
   } 
} 
  1. On Windows it works,
  2. On Linux, the bridge seems to work, but nothing is visible. So I want to know how to make it work on linux.
A: 

SWT heavily depends on native libraries. Double-check that you use different and correct builds for both operating systems.

And double-check if Mozilla (Firefox) is installed on the linux system. SWT.Browser binds to the native HTML rendering engine (Explorer on Windows, Mozilla on Linux system).

And finally: check the SWT FAQ: What do I need to run the SWT Browser inside Eclipse on Linux?

Andreas_D
A: 

If I just run swt brower and do not embed it into canvas. It can show the webpage in linux.So I though the problem is in SWT_AWT bridge. My code is attached below: public class BrowserClass { public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Browser Example"); shell.setSize(620, 500);

ToolBar toolbar = new ToolBar(shell, SWT.NONE);
toolbar.setBounds(5, 5, 200, 30);

ToolItem goButton = new ToolItem(toolbar, SWT.PUSH);
goButton.setText("Go");

ToolItem backButton = new ToolItem(toolbar, SWT.PUSH);
backButton.setText("Back");

ToolItem stopButton = new ToolItem(toolbar, SWT.PUSH);
stopButton.setText("Stop");

final Text text = new Text(shell, SWT.BORDER);
text.setBounds(5, 35, 400, 25);

final Browser browser = new Browser(shell, SWT.NONE);
browser.setBounds(5, 75, 600, 400);

Listener listener = new Listener() {
  public void handleEvent(Event event) {
    ToolItem item = (ToolItem) event.widget;
    String string = item.getText();
    if (string.equals("Back"))
      browser.back();
    else if (string.equals("Stop"))
      browser.stop();
    else if (string.equals("Go"))
      browser.setUrl(text.getText());
  }
};

goButton.addListener(SWT.Selection, listener);
backButton.addListener(SWT.Selection, listener);
stopButton.addListener(SWT.Selection, listener);

text.addListener(SWT.DefaultSelection, new Listener() {
  public void handleEvent(Event e) {
    browser.setUrl(text.getText());
  }
});

shell.open();
browser.setUrl("http://www.google.com");
while (!shell.isDisposed()) {
  if (!display.readAndDispatch())
    display.sleep();
}
display.dispose();

} It can open google websit. But if i use SWT_AWT.new_Shell method. It is not OK.

I cannot embed a swt button in it.

My environment is : mozilla 1.7.7 gtk: gtk2-2.2.4-19 linux: Red Hat Enterprise Linux ES release 3 (Taroon Update 8) uname -a 2.4.21-47.ELsmp #1 SMP Wed Jul 5 20:38:41 EDT 2006 i686 i686 i386 GNU/Linux

han14466
A: 

set sun.awt.xembedserver to true https://bugs.eclipse.org/bugs/show_bug.cgi?id=161911

han14466