Skip to content

Instantly share code, notes, and snippets.

@atechcrew
Created July 9, 2018 16:07
Show Gist options
  • Save atechcrew/d7934eb1017ef41d9340f669976afb2e to your computer and use it in GitHub Desktop.
Save atechcrew/d7934eb1017ef41d9340f669976afb2e to your computer and use it in GitHub Desktop.
Web browser in java using swt. Simple Web Browser in java. Simple web browser.
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class SimpleJavaWebBrowser{
static Browser browser;
static String url = "http://google.com";
public static void main(String[] args) {
System.setProperty("http.agent", "Chrome");
Display display = new Display();
Shell shell = new Shell(display, SWT.TITLE | SWT.CLOSE |SWT.MIN | SWT.MAX | SWT.BORDER);
shell.setSize(500, 500);
shell.setText("Java Web Browser");
shell.setLayout(new FormLayout());
FormData data = new FormData();
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 13);
status.setLayoutData(data);
browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(0,0);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
browser.setUrl(url);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment