WEB VIEW WITH TOGGLE RADIO BUTTON GROUP IN JAVAFX
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class webChooser extends Application
{
@Override
public void start(final Stage stage) throws Exception
{
BorderPane bp=new BorderPane();
HBox hb1=new HBox();
HBox hb2=new HBox();
HBox hb3=new HBox();
//hb.setSpacing(10);
hb1.setPadding(new Insets(10,10,10,10));
hb2.setPadding(new Insets(10,10,10,10));
hb3.setPadding(new Insets(10,10,10,10));
final ToggleGroup group = new ToggleGroup();
RadioButton rb1 = new RadioButton("");
//rb1.setMaxSize(maxWidth, maxHeight);
rb1.setStyle("-fx-background-color: #FFFFFF;");
rb1.setMaxSize(400, 100);
rb1.setToggleGroup(group);
RadioButton rb2 = new RadioButton("");
//rb1.setMaxSize(maxWidth, maxHeight);
rb2.setStyle("-fx-background-color: #FFFFFF;");
rb2.setMaxSize(400, 100);
rb2.setToggleGroup(group);
RadioButton rb3 = new RadioButton("");
//rb1.setMaxSize(maxWidth, maxHeight);
rb3.setStyle("-fx-background-color: #FFFFFF;");
rb3.setMaxSize(400, 100);
rb3.setToggleGroup(group);
//rb1.setSelected(true);
//web view 1
final WebView browser = new WebView();
browser.setMaxSize(400, 100);
webEngine(browser, stage);
hb1.getChildren().addAll(browser,rb1);
//web view 2
final WebView browser2 = new WebView();
browser2.setMaxSize(400, 100);
webEngine(browser2, stage);
hb2.getChildren().addAll(browser2,rb2);
//web view 3
final WebView browser3 = new WebView();
browser3.setMaxSize(400, 100);
webEngine(browser3, stage);
hb3.getChildren().addAll(browser3,rb3);
//browser.setLayoutY(100);
VBox vb=new VBox();
vb.getChildren().addAll(hb1,hb2,hb3);
Scene sc=new Scene(vb);
stage.setScene(sc);
stage.show();
}
public void webEngine(WebView browser,final Stage stage)
{
final WebEngine webEngine = browser.getEngine();
webEngine.getLoadWorker().stateProperty()
.addListener(new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
stage.setTitle(webEngine.getLocation());
}
}
});
webEngine.load("file:///C:/Users/use/Desktop/web.html");
}
public static void main(String args[])
{
launch(args);
}
}
No comments:
Post a Comment