Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38180 > unrolled thread
| Started by | nirp0109@gmail.com |
|---|---|
| First post | 2018-03-14 07:30 -0700 |
| Last post | 2018-03-14 07:30 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: SWT browser in Swing JPanel nirp0109@gmail.com - 2018-03-14 07:30 -0700
| From | nirp0109@gmail.com |
|---|---|
| Date | 2018-03-14 07:30 -0700 |
| Subject | Re: SWT browser in Swing JPanel |
| Message-ID | <eacf7343-ddd2-4d0b-9747-5120bcdf7294@googlegroups.com> |
בתאריך יום שישי, 15 בפברואר 2008 בשעה 16:45:19 UTC+2, מאת Jorge:
> Hi all,
>
> I am trying to use SWT_AWT bridge to embed the SWT browser in a swing
> JPanel.
>
> I am able to do such thing when I embed the SWT shell in a Canvas
> within a Frame, but it does not work when I embed the Canvas in a
> hierarchy of JPanels.
>
> Here is my example code:
>
> /**********/
> import java.awt.BorderLayout;
> import java.awt.Canvas;
>
> import javax.swing.JFrame;
> import javax.swing.JPanel;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.awt.SWT_AWT;
> import org.eclipse.swt.browser.Browser;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.layout.FormAttachment;
> import org.eclipse.swt.layout.FormData;
> import org.eclipse.swt.layout.FormLayout;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> public class BrowserinSwingPanel {
>
> public static void main(String[] a) {
> System.setProperty ( "sun.awt.xembedserver", "true" );
> JFrame frame = new JFrame("SWING browser"); // java.awt.Frame
> JPanel panel = new JPanel();
> JPanel panel2 = new JPanel();
> JPanel panel3 = new JPanel();
> Canvas canvas = new Canvas(); // java.awt.Canvas
>
> panel.add(panel2, BorderLayout.CENTER);
> panel2.add(panel3, BorderLayout.CENTER);
> panel3.add(canvas, BorderLayout.CENTER);
> frame.add (panel, BorderLayout.CENTER );
> panel.setBackground ( new java.awt.Color(78978979) );
> panel3.setBackground ( new java.awt.Color(453) );
> canvas.setBackground ( new java.awt.Color(2134324) );
> // invoke the AWT frame rendering by making the frame visible
> // This starts the EDT
> panel3.setVisible(true);
> panel2.setVisible(true);
> panel.setVisible ( true );
> frame.setVisible(true);
> frame.setBounds ( 0, 0, 500, 500 );
> canvas.setBounds ( 0,0,400,400 );
>
> final Display display = new Display(); // display object to manage
> SWT lifecycle.
> final Shell shell = SWT_AWT.new_Shell(display, canvas);
>
> shell.setSize(400, 400);
>
> shell.setLayout(new FormLayout());
> shell.setBackground ( new Color(display,255,0,0) );
> Composite controls = new Composite(shell, SWT.NONE);
> FormData data = new FormData();
> data.top = new FormAttachment(0, 0);
> data.left = new FormAttachment(0, 0);
> data.right = new FormAttachment(100, 0);
> controls.setLayoutData(data);
>
> final Browser browser = new Browser(shell, SWT.MOZILLA);
> browser.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> data = new FormData();
> data.top = new FormAttachment(controls);
> data.bottom = new FormAttachment(100, 0);
> data.left = new FormAttachment(0, 0);
> data.right = new FormAttachment(100, 0);
> browser.setLayoutData(data);
>
> controls.setLayout(new GridLayout(6, false));
>
> Button button = new Button(controls, SWT.PUSH);
> button.setText("Back");
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> browser.back();
> }
> });
>
> button = new Button(controls, SWT.PUSH);
> button.setText("Forward");
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> browser.forward();
> }
> });
>
> button = new Button(controls, SWT.PUSH);
> button.setText("Refresh");
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> browser.refresh();
> }
> });
>
> button = new Button(controls, SWT.PUSH);
> button.setText("Stop");
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> browser.stop();
> }
> });
>
> final Text url = new Text(controls, SWT.BORDER);
> url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
> url.setFocus();
>
> button = new Button(controls, SWT.PUSH);
> button.setText("Go");
> button.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent event) {
> browser.setUrl(url.getText());
> }
> });
>
> shell.setDefaultButton(button);
>
> browser.setUrl ( "www.google.com" );
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
>
> /*********/
>
> Does anyone know if it is possible? Because the code does not fail,
> but the browser is not displayed at all although the Shell is
> displayed.
>
> Any ideas would be very appreciated.
>
> Thanks!
Have you found a solution?
Back to top | Article view | comp.lang.java.programmer
csiph-web