2

I am implementing a SWT Browser in my project to display HTML Pages. When user right clicks on this browser it shows a popup menu with functionalities like "Print", "Print View". Can this be done with separate buttons, if I place them on a Toolbar?

enter image description here

Another functionality of the browser control is using "Ctrl+F", which bring a find dialogue. Can this dialogue be called using a button?

enter image description here

please help me?

Baz
  • 36,440
  • 11
  • 68
  • 94
Abhit
  • 481
  • 6
  • 19

1 Answers1

2

You can achieve some of those goals by executing JavaScript when the Button is pressed.

Here is an example for the print dialog:

public static void main(String[] args)
{
    Display display = Display.getDefault();
    final Shell shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(1, false));

    final Browser browser = new Browser(shell, SWT.NONE);
    browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Search");

    button.addListener(SWT.Selection, new Listener()
    {
        @Override
        public void handleEvent(Event arg0)
        {
            browser.execute("window.print()");
        }
    });

    shell.pack();
    shell.setSize(600, 400);
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

Just search online how to achieve the other functionalities that you want to add by using javascript.

Baz
  • 36,440
  • 11
  • 68
  • 94
  • thanks Baz, but i want a print preview of browser.how this acheive using javascript – Abhit Sep 30 '13 at 04:56
  • @Abhit http://stackoverflow.com/questions/230205/how-can-print-preview-be-called-from-javascript – Baz Sep 30 '13 at 06:12