List of usage examples for javafx.scene.layout Pane Pane
public Pane()
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 260, 80); stage.setScene(scene);/* ww w . j av a 2 s . c o m*/ stage.setTitle(""); VBox vb = new VBox(); Pane canvas = new Pane(); canvas.setStyle("-fx-background-color: black;"); canvas.setPrefSize(200, 200); Circle circle = new Circle(50, Color.BLUE); circle.relocate(20, 20); Rectangle rectangle = new Rectangle(100, 100, Color.RED); rectangle.relocate(70, 70); canvas.getChildren().addAll(circle, rectangle); vb.getChildren().add(canvas); scene.setRoot(vb); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Canvas canvas = new Canvas(300, 100); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setLineWidth(2.0);//from ww w .j a v a2s. c o m gc.setFill(Color.RED); gc.strokeRoundRect(10, 10, 50, 50, 10, 10); gc.fillOval(70, 10, 50, 20); gc.strokeText("Hello Canvas", 150, 20); Pane root = new Pane(); root.getChildren().add(canvas); Scene scene = new Scene(root); stage.setScene(scene); stage.setTitle(""); stage.show(); }
From source file:ui.ChoseFonctionnalite.java
private void initUI() { Pane root = new Pane(); root.setBackground(new Background(new BackgroundImage(new Image("resource/background.jpg"), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, new BackgroundSize(530, 400, true, true, true, true)))); JFXButton serveur = new JFXButton("SERVEUR"); serveur.setCursor(Cursor.HAND); serveur.setMinSize(171, 57);/*from w w w . ja va 2 s . c om*/ serveur.setLayoutX(179); serveur.setLayoutY(90); serveur.setFont(new Font(27)); serveur.setStyle("-fx-background-color: #9E21FF;"); serveur.setOnAction(event -> { startServerMode(); }); JFXButton client = new JFXButton("CLIENT"); client.setCursor(Cursor.HAND); client.setMinSize(171, 57); client.setLayoutX(179); client.setLayoutY(197); client.setFont(new Font(27)); client.setStyle("-fx-background-color: #9E21FF;"); client.setOnAction(event -> { startClientMode(event); }); Label info = new Label("choisir la maniere d'utiliser virtual remote"); info.setMinSize(529, 43); info.setLayoutX(10); info.setLayoutY(14); info.setFont(new Font("Algerian", 20)); root.getChildren().add(client); root.getChildren().add(serveur); root.getChildren().add(info); Scene scene = new Scene(root, 530, 400); stage.setTitle("Fontionnalit"); stage.setScene(scene); stage.setResizable(false); stage.initStyle(StageStyle.DECORATED); stage.setOnCloseRequest(event -> { System.exit(1); }); stage.show(); }
From source file:org.mskcc.shenkers.control.alignment.VerticalOverlayNGTest.java
@Override public void start(Stage stage) throws Exception { Pane r1 = new Pane(); Text lbl = new Text("H"); List<Node> collect = "ABcDEFGHIJKL".chars().mapToObj(new IntFunction<StretchStringPane>() { @Override/*from w ww . j a v a2 s . c o m*/ public StretchStringPane apply(int value) { return new StretchStringPane("" + ((char) value)); } }).collect(Collectors.toList()); VerticalOverlay ao = new VerticalOverlay(); ao.setChildren(collect); ao.flip(); Scene scene = new Scene(ao.getContent(), 300, 300, Color.GRAY); stage.setTitle("JavaFX Scene Graph Demo"); stage.setScene(scene); stage.show(); }
From source file:eu.mihosoft.vfxwebkit.DemoApplication.java
@Override public void start(Stage primaryStage) { Path tmpFile = null;//from ww w . j a va 2 s . c o m try { tmpFile = Files.createTempDirectory("eu.mihosoft.vfxwebkit"); } catch (IOException ex) { Logger.getLogger(DemoApplication.class.getName()).log(Level.SEVERE, null, ex); System.exit(1); } try { FileUtils.copyDirectory(new File("src/main/resources/eu/mihosoft/vfxwebkit/"), tmpFile.toFile()); // FileUtils.copyDirectory( // new File("/Users/miho/Qt/qt/5.5/clang_64/lib/"), // new File(tmpFile.toFile(),"native/osx/")); } catch (IOException ex) { Logger.getLogger(DemoApplication.class.getName()).log(Level.SEVERE, null, ex); } File libraryPath = new File(tmpFile.toFile(), "native/osx/libvfxwebkit.1.0.0.dylib"); System.load(libraryPath.getAbsolutePath()); // new Thread(()->{NativeBinding.INSTANCE.init();}).start(); // NativeBinding.INSTANCE.init(); VFXWebNode webView = VFXWebNode.newInstance(VFXWebNode.NodeType.JFX_DIRECT_BUFFER); // webView.getEngine().load("http://learningwebgl.com/lessons/lesson04/index.html"); Window w = new Window("Qt WebKit & WebGL inside JavaFX"); w.setPrefSize(600, 440); w.getContentPane().getChildren().add(webView.getNode()); // Window w2 = new Window("JavaFX WebView"); // w2.setLayoutX(620); // w2.setPrefSize(600, 440); // // WebView fxview = new WebView(); // fxview.getEngine().load("http://learningwebgl.com/lessons/lesson04/index.html"); // // w2.getContentPane().getChildren().add(fxview); Pane root = new Pane(); root.getChildren().add(w); Scene scene = new Scene(root, 1280, 1024); primaryStage.setTitle("Hello Native Qt, hello WebGL!"); primaryStage.setScene(scene); primaryStage.show(); }
From source file:net.rptools.layercontrol.LayerStackLayer.java
/** * Add a layer./*from w w w. j a v a 2 s. co m*/ * @param i index to add at * @param layer layer to add */ @ThreadPolicy(ThreadPolicy.ThreadId.ANY) public synchronized void addLayer(final int i, final Layer layer) { if (!Platform.isFxApplicationThread()) { Platform.runLater(new Runnable() { @Override public void run() { addLayer(i, layer); } }); } // Now on JFX thread Pane pane = new Pane(); final String resource = "layer" + layer.getName() + ".fxml"; try { pane = component.getFramework().getFXMLLoader(layer.getClass().getResource(resource)).load(); } catch (final Exception e) { LOGGER.warn("no layer pane found resource={}", resource); } pane.getStyleClass().add(layer.getName().toLowerCase()); pane.setId(StringUtils.uncapitalize(layer.getName())); pane.minWidthProperty().bind(getDrawable().widthProperty()); pane.minHeightProperty().bind(getDrawable().heightProperty()); final int size = getDrawable().getChildren().size(); getDrawable().getChildren().add(size - i, pane); layer.setDrawable(pane); }
From source file:nl.rivm.cib.episim.model.disease.infection.MSEIRSPlot.java
@Override public void start(final Stage stage) { final SIRConfig conf = ConfigFactory.create(SIRConfig.class); final double[] t = conf.t(); final long[] pop = conf.population(); final double n0 = Arrays.stream(pop).sum(); final String[] colors = conf.colors(), colors2 = conf.colors2(); final Pane plot = new Pane(); plot.setPrefSize(400, 300);// w w w . j a v a2s .co m plot.setMinSize(50, 50); final NumberAxis xAxis = new NumberAxis(t[0], t[1], (t[1] - t[0]) / 10); final NumberAxis yAxis = new NumberAxis(0, n0, n0 / 10); final Pane axes = new Pane(); axes.prefHeightProperty().bind(plot.heightProperty()); axes.prefWidthProperty().bind(plot.widthProperty()); xAxis.setSide(Side.BOTTOM); xAxis.setMinorTickVisible(false); xAxis.setPrefWidth(axes.getPrefWidth()); xAxis.prefWidthProperty().bind(axes.widthProperty()); xAxis.layoutYProperty().bind(axes.heightProperty()); yAxis.setSide(Side.LEFT); yAxis.setMinorTickVisible(false); yAxis.setPrefHeight(axes.getPrefHeight()); yAxis.prefHeightProperty().bind(axes.heightProperty()); yAxis.layoutXProperty().bind(Bindings.subtract(1, yAxis.widthProperty())); axes.getChildren().setAll(xAxis, yAxis); final Label lbl = new Label(String.format("R0=%.1f, recovery=%.1ft\nSIR(0)=%s", conf.reproduction(), conf.recovery(), Arrays.toString(pop))); lbl.setTextAlignment(TextAlignment.CENTER); lbl.setTextFill(Color.WHITE); final Path[] deterministic = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors[i]); final Path path = deterministic[i]; path.setStroke(color.deriveColor(0, 1, 1, 0.6)); path.setStrokeWidth(2); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); plot.getChildren().setAll(axes); // fill paths with integration estimates final double xl = xAxis.getLowerBound(), sx = plot.getPrefWidth() / (xAxis.getUpperBound() - xl), yh = plot.getPrefHeight(), sy = yh / (yAxis.getUpperBound() - yAxis.getLowerBound()); final TreeMap<Double, Integer> iDeterministic = new TreeMap<>(); MSEIRSTest.deterministic(conf, () -> new DormandPrince853Integrator(1.0E-8, 10, 1.0E-20, 1.0E-20)) .subscribe(yt -> { iDeterministic.put(yt.getKey(), deterministic[0].getElements().size()); final double[] y = yt.getValue(); final double x = (yt.getKey() - xl) * sx; for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final PathElement di = deterministic[i].getElements().isEmpty() ? new MoveTo(x, yi) : new LineTo(x, yi); deterministic[i].getElements().add(di); } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(deterministic)); final Path[] stochasticTau = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors[i]); final Path path = stochasticTau[i]; path.setStroke(color); path.setStrokeWidth(1); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); final TreeMap<Double, Integer> iStochasticTau = new TreeMap<>(); MSEIRSTest.stochasticGillespie(conf).subscribe(yt -> { final double x = (yt.getKey() - xl) * sx; iStochasticTau.put(yt.getKey(), stochasticTau[0].getElements().size()); final long[] y = yt.getValue(); for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final ObservableList<PathElement> path = stochasticTau[i].getElements(); if (path.isEmpty()) { path.add(new MoveTo(x, yi)); // first } else { final PathElement last = path.get(path.size() - 1); final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY(); path.add(new LineTo(x, y_prev)); path.add(new LineTo(x, yi)); } } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticTau)); final Path[] stochasticRes = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors2[i]); final Path path = stochasticRes[i]; path.setStroke(color); path.setStrokeWidth(1); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); final TreeMap<Double, Integer> iStochasticRes = new TreeMap<>(); MSEIRSTest.stochasticSellke(conf).subscribe(yt -> { final double x = (yt.getKey() - xl) * sx; iStochasticRes.put(yt.getKey(), stochasticRes[0].getElements().size()); final long[] y = yt.getValue(); for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final ObservableList<PathElement> path = stochasticRes[i].getElements(); if (path.isEmpty()) { path.add(new MoveTo(x, yi)); // first } else { final PathElement last = path.get(path.size() - 1); final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY(); path.add(new LineTo(x, y_prev)); path.add(new LineTo(x, yi)); } } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticRes)); // auto-scale on stage/plot resize // FIXME scaling around wrong origin, use ScatterChart? // xAxis.widthProperty() // .addListener( (ChangeListener<Number>) ( observable, // oldValue, newValue ) -> // { // final double scale = ((Double) newValue) // / plot.getPrefWidth(); // plot.getChildren().filtered( n -> n instanceof Path ) // .forEach( n -> // { // final Path path = (Path) n; // path.setScaleX( scale ); // path.setTranslateX( (path // .getBoundsInParent().getWidth() // - path.getLayoutBounds().getWidth()) // / 2 ); // } ); // } ); // plot.heightProperty() // .addListener( (ChangeListener<Number>) ( observable, // oldValue, newValue ) -> // { // final double scale = ((Double) newValue) // / plot.getPrefHeight(); // plot.getChildren().filtered( n -> n instanceof Path ) // .forEach( n -> // { // final Path path = (Path) n; // path.setScaleY( scale ); // path.setTranslateY( // (path.getBoundsInParent() // .getHeight() * (scale - 1)) // / 2 ); // } ); // } ); final StackPane layout = new StackPane(lbl, plot); layout.setAlignment(Pos.TOP_CENTER); layout.setPadding(new Insets(50)); layout.setStyle("-fx-background-color: rgb(35, 39, 50);"); final Line vertiCross = new Line(); vertiCross.setStroke(Color.SILVER); vertiCross.setStrokeWidth(1); vertiCross.setVisible(false); axes.getChildren().add(vertiCross); final Tooltip tip = new Tooltip(""); tip.setAutoHide(false); tip.hide(); axes.setOnMouseExited(ev -> tip.hide()); axes.setOnMouseMoved(ev -> { final Double x = (Double) xAxis.getValueForDisplay(ev.getX()); if (x > xAxis.getUpperBound() || x < xAxis.getLowerBound()) { tip.hide(); vertiCross.setVisible(false); return; } final Double y = (Double) yAxis.getValueForDisplay(ev.getY()); if (y > yAxis.getUpperBound() || y < yAxis.getLowerBound()) { tip.hide(); vertiCross.setVisible(false); return; } final double xs = xAxis.getDisplayPosition(x); vertiCross.setStartX(xs); vertiCross.setStartY(yAxis.getDisplayPosition(0)); vertiCross.setEndX(xs); vertiCross.setEndY(yAxis.getDisplayPosition(yAxis.getUpperBound())); vertiCross.setVisible(true); final int i = (iDeterministic.firstKey() > x ? iDeterministic.firstEntry() : iDeterministic.floorEntry(x)).getValue(); final Object[] yi = Arrays.stream(deterministic).mapToDouble(p -> getY(p, i)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 1)).toArray(); final int j = (iStochasticTau.firstKey() > x ? iStochasticTau.firstEntry() : iStochasticTau.floorEntry(x)).getValue(); final Object[] yj = Arrays.stream(stochasticTau).mapToDouble(p -> getY(p, j)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray(); final int k = (iStochasticRes.firstKey() > x ? iStochasticRes.firstEntry() : iStochasticRes.floorEntry(x)).getValue(); final Object[] yk = Arrays.stream(stochasticRes).mapToDouble(p -> getY(p, k)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray(); final String txt = String.format("SIR(t=%.1f)\n" + "~det%s\n" + "~tau%s\n" + "~res%s", x, Arrays.toString(yi), Arrays.toString(yj), Arrays.toString(yk)); tip.setText(txt); tip.show(axes, ev.getScreenX() - ev.getSceneX() + xs, ev.getScreenY() + 15); }); try { stage.getIcons().add(new Image(FileUtil.toInputStream("icon.jpg"))); } catch (final IOException e) { LOG.error("Problem", e); } stage.setTitle("Deterministic vs. Stochastic"); stage.setScene(new Scene(layout, Color.rgb(35, 39, 50))); // stage.setOnHidden( ev -> tip.hide() ); stage.show(); }
From source file:MediaControl.java
public MediaControl(final MediaPlayer mp) { this.mp = mp; setStyle("-fx-background-color: #bfc2c7;"); mediaView = new MediaView(mp); Pane mvPane = new Pane() { };/*from w w w .j a v a 2 s. co m*/ mvPane.getChildren().add(mediaView); mvPane.setStyle("-fx-background-color: black;"); setCenter(mvPane); mediaBar = new HBox(); mediaBar.setAlignment(Pos.CENTER); mediaBar.setPadding(new Insets(5, 10, 5, 10)); BorderPane.setAlignment(mediaBar, Pos.CENTER); final Button playButton = new Button(">"); playButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { Status status = mp.getStatus(); if (status == Status.UNKNOWN || status == Status.HALTED) { // don't do anything in these states return; } if (status == Status.PAUSED || status == Status.READY || status == Status.STOPPED) { // rewind the movie if we're sitting at the end if (atEndOfMedia) { mp.seek(mp.getStartTime()); atEndOfMedia = false; } mp.play(); } else { mp.pause(); } } }); mp.currentTimeProperty().addListener(new InvalidationListener() { public void invalidated(Observable ov) { updateValues(); } }); mp.setOnPlaying(new Runnable() { public void run() { if (stopRequested) { mp.pause(); stopRequested = false; } else { playButton.setText("||"); } } }); mp.setOnPaused(new Runnable() { public void run() { System.out.println("onPaused"); playButton.setText(">"); } }); mp.setOnReady(new Runnable() { public void run() { duration = mp.getMedia().getDuration(); updateValues(); } }); mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1); mp.setOnEndOfMedia(new Runnable() { public void run() { if (!repeat) { playButton.setText(">"); stopRequested = true; atEndOfMedia = true; } } }); mediaBar.getChildren().add(playButton); // Add spacer Label spacer = new Label(" "); mediaBar.getChildren().add(spacer); // Add Time label Label timeLabel = new Label("Time: "); mediaBar.getChildren().add(timeLabel); // Add time slider timeSlider = new Slider(); HBox.setHgrow(timeSlider, Priority.ALWAYS); timeSlider.setMinWidth(50); timeSlider.setMaxWidth(Double.MAX_VALUE); timeSlider.valueProperty().addListener(new InvalidationListener() { public void invalidated(Observable ov) { if (timeSlider.isValueChanging()) { // multiply duration by percentage calculated by slider position mp.seek(duration.multiply(timeSlider.getValue() / 100.0)); } } }); mediaBar.getChildren().add(timeSlider); // Add Play label playTime = new Label(); playTime.setPrefWidth(130); playTime.setMinWidth(50); mediaBar.getChildren().add(playTime); // Add the volume label Label volumeLabel = new Label("Vol: "); mediaBar.getChildren().add(volumeLabel); // Add Volume slider volumeSlider = new Slider(); volumeSlider.setPrefWidth(70); volumeSlider.setMaxWidth(Region.USE_PREF_SIZE); volumeSlider.setMinWidth(30); volumeSlider.valueProperty().addListener(new InvalidationListener() { public void invalidated(Observable ov) { if (volumeSlider.isValueChanging()) { mp.setVolume(volumeSlider.getValue() / 100.0); } } }); mediaBar.getChildren().add(volumeSlider); setBottom(mediaBar); }
From source file:ui.ChoseFonctionnalite.java
private void startClientMode(ActionEvent eventT) { //File config = new File("resource/config.json"); String host = ""; String port = "8000"; Stage stageModal = new Stage(); Pane root = new Pane(); root.setBackground(new Background(new BackgroundImage(new Image("resource/background.jpg"), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, new BackgroundSize(530, 400, true, true, true, true)))); stageModal.setScene(new Scene(root, 200, 200)); stageModal.initStyle(StageStyle.UTILITY); Label adresse = new Label("Adresse serveur:"); adresse.setLayoutX(10);//from w w w . ja va 2s .c o m adresse.setLayoutY(10); adresse.setFont(Font.font("Arial", 16)); JFXTextField adresseInput = new JFXTextField("127.0.0.1"); adresseInput.setPrefWidth(180); adresseInput.setLayoutX(10); adresseInput.setLayoutY(40); JFXButton valider = new JFXButton("Se connecter"); valider.setCursor(Cursor.HAND); valider.setMinSize(100, 30); valider.setLayoutX(20); valider.setLayoutY(130); valider.setFont(new Font(20)); valider.setStyle("-fx-background-color: #9E21FF;"); valider.setOnAction(event -> { if (adresseInput.getText() != "") { stageModal.close(); InitClient initializeClient = new InitClient(stage, adresseInput.getText(), port); } }); root.getChildren().add(valider); root.getChildren().add(adresse); root.getChildren().add(adresseInput); stageModal.setTitle("Adresse serveur"); stageModal.initModality(Modality.WINDOW_MODAL); stageModal.initOwner(((Node) eventT.getSource()).getScene().getWindow()); stageModal.show(); }
From source file:Main.java
@Override public void start(final Stage stage) { final Node loginPanel = makeDraggable(createLoginPanel()); final Node confirmationPanel = makeDraggable(createConfirmationPanel()); final Node progressPanel = makeDraggable(createProgressPanel()); loginPanel.relocate(0, 0);//from www . ja va 2 s. c o m confirmationPanel.relocate(0, 67); progressPanel.relocate(0, 106); final Pane panelsPane = new Pane(); panelsPane.getChildren().addAll(loginPanel, confirmationPanel, progressPanel); final BorderPane sceneRoot = new BorderPane(); BorderPane.setAlignment(panelsPane, Pos.TOP_LEFT); sceneRoot.setCenter(panelsPane); final CheckBox dragModeCheckbox = new CheckBox("Drag mode"); BorderPane.setMargin(dragModeCheckbox, new Insets(6)); sceneRoot.setBottom(dragModeCheckbox); dragModeActiveProperty.bind(dragModeCheckbox.selectedProperty()); final Scene scene = new Scene(sceneRoot, 400, 300); stage.setScene(scene); stage.setTitle("Draggable Panels Example"); stage.show(); }