Last active
August 29, 2015 14:05
-
-
Save JakubOboza/15a4f1a2d906b14d7147 to your computer and use it in GitHub Desktop.
super simple web browser using javafx.
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 javafx.application.Application | |
import javafx.geometry.HPos | |
import javafx.geometry.VPos | |
import javafx.scene.Node | |
import javafx.scene.Scene | |
import javafx.scene.layout.HBox | |
import javafx.scene.layout.Priority | |
import javafx.scene.layout.Region | |
import javafx.scene.paint.Color | |
import javafx.scene.web.WebEngine | |
import javafx.scene.web.WebView | |
import javafx.stage.Stage | |
class WebViewSample extends Application { | |
var scene: Scene = null | |
override def start(stage: Stage) { | |
stage.setTitle(TryOutBrowser.url) | |
scene = new Scene(new Browser(),1024,800, Color.web("#666970")) | |
stage.setScene(scene) | |
scene.getStylesheets().add("webviewsample/BrowserToolbar.css") | |
stage.show() | |
} | |
} | |
object TryOutBrowser { | |
// not functional and dirty | |
var url: String = "http://google.com" | |
def main(args: Array[String]) { | |
if (args.length == 1){ url = args(0) } | |
Application.launch(classOf[WebViewSample], args: _*) | |
} | |
} | |
// lol lets implement Browser Class implementation | |
class Browser extends Region { | |
val browser = new WebView() | |
val webEngine = browser.getEngine() | |
getStyleClass().add("browser") | |
webEngine.load(TryOutBrowser.url) | |
getChildren().add(browser) | |
def createSpacer(): Node = { | |
val spacer = new Region() | |
HBox.setHgrow(spacer, Priority.ALWAYS) | |
return spacer | |
} | |
override def layoutChildren() { | |
val w = getWidth() | |
val h = getHeight() | |
layoutInArea(browser,0,0,w,h,0, HPos.CENTER, VPos.CENTER) | |
} | |
override def computePrefWidth(height: Double) : Double = { | |
return 750 | |
} | |
override def computePrefHeight(double: Double) : Double = { | |
return 500 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment