Created
July 9, 2018 16:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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