Java Code Examples for javafx.scene.image.ImageView#setPreserveRatio()
The following examples show how to use
javafx.scene.image.ImageView#setPreserveRatio() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedImage.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
Node createNode() { String imageUrl; try { imageUrl = (basePath != null) ? basePath.resolve(url).toUri().toString() : "file:" + url; } catch (InvalidPathException ex) { return createErrorNode(); } // load image Image image = loadImage(imageUrl); if (image.isError()) return createErrorNode(); // loading failed // create image view ImageView view = new ImageView(image); view.setPreserveRatio(true); view.setFitWidth(Math.min(image.getWidth(),MAX_SIZE)); view.setFitHeight(Math.min(image.getHeight(),MAX_SIZE)); return view; }
Example 2
Source File: BackGridPane.java From img2latex-mathpix with Apache License 2.0 | 6 votes |
/** * Method to set ImageView style and add a BorderPane for border plotting. * * @param imageView ImageView to be customised. * @return customised ImageView with BorderPane. */ private BorderPane setImageViewBorder(ImageView imageView) { // preserve image ratio imageView.setPreserveRatio(true); // maximum width is 390 maximum height is 150 // image larger than the above size will be scaled down imageView.setFitWidth(PREFERRED_WIDTH); imageView.setFitHeight(PREFERRED_HEIGHT); var borderPane = new BorderPane(imageView); // use BorderPane to add a border stroke to the ImageView borderPane.setBorder(new Border(PANE_BORDER_STROKE)); borderPane.setPrefSize(PREFERRED_WIDTH, 110); return borderPane; }
Example 3
Source File: HelloFX.java From client-samples with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void start(Stage stage) { String javaVersion = System.getProperty("java.version"); String javafxVersion = System.getProperty("javafx.version"); Label label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + "."); ImageView imageView = new ImageView(new Image(HelloFX.class.getResourceAsStream("/hellofx/openduke.png"))); imageView.setFitHeight(200); imageView.setPreserveRatio(true); VBox root = new VBox(30, imageView, label); root.setAlignment(Pos.CENTER); Scene scene = new Scene(root, 640, 480); scene.getStylesheets().add(HelloFX.class.getResource("styles.css").toExternalForm()); stage.setScene(scene); stage.show(); }
Example 4
Source File: RefundController.java From HealthPlus with Apache License 2.0 | 6 votes |
public void fillRefundTable() { final ObservableList<Refund> data = FXCollections.observableArrayList(); ArrayList<ArrayList<String>> refundData = cashier.cashier.getWaitingRefunds(); int size = refundData.size(); for(int i = 1; i < size; i++) { String refundId = refundData.get(i).get(0); String billId = refundData.get(i).get(1); //String paymentType = refundData.get(i).get(2); String reason = refundData.get(i).get(3); String amount = refundData.get(i).get(4); String date = refundData.get(i).get(5); Image img2 = new Image(getClass().getResource("/imgs/refund.png").toString(), true); ImageView imageView = new ImageView(img2); imageView.setFitHeight(25); imageView.setFitWidth(25); imageView.setPreserveRatio(true); data.add(new Refund(refundId,date,billId,reason,amount,imageView)); } refundTable.setItems(data); }
Example 5
Source File: TileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
protected void initGraphics() { // Set initial size if (Double.compare(tile.getPrefWidth(), 0.0) <= 0 || Double.compare(tile.getPrefHeight(), 0.0) <= 0 || Double.compare(tile.getWidth(), 0.0) <= 0 || Double.compare(tile.getHeight(), 0.0) <= 0) { if (tile.getPrefWidth() > 0 && tile.getPrefHeight() > 0) { tile.setPrefSize(tile.getPrefWidth(), tile.getPrefHeight()); } else { tile.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } } shadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 3, 0, 0, 0); backgroundImageView = new ImageView(); backgroundImageView.setPreserveRatio(true); backgroundImageView.setMouseTransparent(true); if (null == tile.getBackgroundImage()) { enableNode(backgroundImageView, false); } else { backgroundImageView.setImage(tile.getBackgroundImage()); enableNode(backgroundImageView, true); } notifyRegion = new NotifyRegion(); enableNode(notifyRegion, false); infoRegion = new InfoRegion(); infoRegion.setPickOnBounds(false); enableNode(infoRegion, false); lowerRightRegion = new LowerRightRegion(); enableNode(lowerRightRegion, false); pane = new Pane(backgroundImageView, notifyRegion, infoRegion, lowerRightRegion); pane.getStyleClass().add("tile"); pane.setBorder(new Border(new BorderStroke(tile.getBorderColor(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(tile.getBorderWidth())))); pane.setBackground(new Background(new BackgroundFill(tile.getBackgroundColor(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY))); getChildren().setAll(pane); }
Example 6
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image addShadowFx(Image image, int shadow, Color color) { try { if (image == null || shadow <= 0) { return null; } double imageWidth = image.getWidth(), imageHeight = image.getHeight(); Group group = new Group(); Scene s = new Scene(group); ImageView view = new ImageView(image); view.setPreserveRatio(true); view.setFitWidth(imageWidth); view.setFitHeight(imageHeight); DropShadow dropShadow = new DropShadow(); dropShadow.setOffsetX(shadow); dropShadow.setOffsetY(shadow); dropShadow.setColor(color); view.setEffect(dropShadow); group.getChildren().add(view); SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); WritableImage newImage = group.snapshot(parameters, null); return newImage; } catch (Exception e) { // logger.error(e.toString()); return null; } }
Example 7
Source File: SlideThumbnail.java From Quelea with GNU General Public License v3.0 | 5 votes |
public SlideThumbnail(ImageGroupSlide slide, int num) { this.num = num; this.slide = slide; image = new ImageView(slide.getImage()); image.setFitWidth(QueleaProperties.get().getThumbnailSize()); image.setPreserveRatio(true); image.setSmooth(true); image.setCache(true); setTop(image); setCenter(new Label(Integer.toString(num))); }
Example 8
Source File: ImagePropertiesSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public ImagePropertiesSample() { //we can set image properties directly during creation ImageView sample1 = new ImageView(new Image(url, 30, 70, false, true)); ImageView sample2 = new ImageView(new Image(url)); //image can be resized to preferred width sample2.setFitWidth(200); sample2.setPreserveRatio(true); ImageView sample3 = new ImageView(new Image(url)); //image can be resized to preferred height sample3.setFitHeight(20); sample3.setPreserveRatio(true); ImageView sample4 = new ImageView(new Image(url)); //one can resize image without preserving ratio between height and width sample4.setFitWidth(40); sample4.setFitHeight(80); sample4.setPreserveRatio(false); sample4.setSmooth(true); //the usage of the better filter ImageView sample5 = new ImageView(new Image(url)); sample5.setFitHeight(60); sample5.setPreserveRatio(true); //viewport is used for displaying the part of image Rectangle2D rectangle2D = new Rectangle2D(50, 200, 120, 60); sample5.setViewport(rectangle2D); //add the imageviews to layout HBox hBox = new HBox(); hBox.setSpacing(10); hBox.getChildren().addAll(sample1, sample3, sample4, sample5); //show the layout VBox vb = new VBox(10); vb.getChildren().addAll(hBox, sample2); getChildren().add(vb); }
Example 9
Source File: ImagePropertiesSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public ImagePropertiesSample() { //we can set image properties directly during creation ImageView sample1 = new ImageView(new Image(url, 30, 70, false, true)); ImageView sample2 = new ImageView(new Image(url)); //image can be resized to preferred width sample2.setFitWidth(200); sample2.setPreserveRatio(true); ImageView sample3 = new ImageView(new Image(url)); //image can be resized to preferred height sample3.setFitHeight(20); sample3.setPreserveRatio(true); ImageView sample4 = new ImageView(new Image(url)); //one can resize image without preserving ratio between height and width sample4.setFitWidth(40); sample4.setFitHeight(80); sample4.setPreserveRatio(false); sample4.setSmooth(true); //the usage of the better filter ImageView sample5 = new ImageView(new Image(url)); sample5.setFitHeight(60); sample5.setPreserveRatio(true); //viewport is used for displaying the part of image Rectangle2D rectangle2D = new Rectangle2D(50, 200, 120, 60); sample5.setViewport(rectangle2D); //add the imageviews to layout HBox hBox = new HBox(); hBox.setSpacing(10); hBox.getChildren().addAll(sample1, sample3, sample4, sample5); //show the layout VBox vb = new VBox(10); vb.getChildren().addAll(hBox, sample2); getChildren().add(vb); }
Example 10
Source File: CountryLabel.java From VickyWarAnalyzer with MIT License | 5 votes |
public CountryLabel(Country country) { super(country.getOfficialName()); tag = country.getTag(); ImageView iv2 = new ImageView(country.getFlag()); iv2.setFitWidth(32); // 30 to 35 looks good iv2.setPreserveRatio(true); iv2.setSmooth(true); iv2.setCache(true); setGraphic(iv2); setContentDisplay(ContentDisplay.LEFT); }
Example 11
Source File: DefaultConversationSenderProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public Region createContent() { Region region = null; try { if (senderLabels.size() == 1) { region = new SelectableLabel(senderLabels.get(0), false, "-fx-text-fill: #cccccc;", null, null); } else { final VBox content = new VBox(-5.0); content.setAlignment(Pos.CENTER_LEFT); for (final String senderLabel : senderLabels) { content.getChildren().add(new SelectableLabel(senderLabel, false, "-fx-text-fill: #cccccc;", null, null)); } region = content; } if (iconImage != null) { final BorderPane borderPane = new BorderPane(); borderPane.setCenter(region); final ImageView iconView = new ImageView(iconImage); iconView.setFitHeight(32); iconView.setPreserveRatio(true); borderPane.setLeft(iconView); region = borderPane; } } catch (Exception ex) { LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex); } return region; }
Example 12
Source File: ImageViewTableCell.java From OpenLabeler with Apache License 2.0 | 5 votes |
public ImageViewTableCell() { setAlignment(Pos.CENTER); setPrefSize(VIEW_SIZE, VIEW_SIZE); imageView = new ImageView(); imageView.setFitHeight(VIEW_SIZE); imageView.setFitWidth(VIEW_SIZE); imageView.setPreserveRatio(true); setGraphic(imageView); }
Example 13
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 4 votes |
public static Image addMarginsFx2(Image image, Color color, int MarginWidth, boolean addTop, boolean addBottom, boolean addLeft, boolean addRight) { try { if (image == null || MarginWidth <= 0) { return image; } Group group = new Group(); double imageWidth = image.getWidth(), imageHeight = image.getHeight(); double totalWidth = image.getWidth(), totalHeight = image.getHeight(); ImageView view = new ImageView(image); view.setPreserveRatio(true); view.setFitWidth(imageWidth); view.setFitHeight(imageHeight); if (addLeft) { view.setX(MarginWidth); totalWidth += MarginWidth; } else { view.setX(0); } if (addTop) { view.setY(MarginWidth); totalHeight += MarginWidth; } else { view.setY(0); } if (addBottom) { totalHeight += MarginWidth; } if (addRight) { totalWidth += MarginWidth; } group.getChildren().add(view); Blend blend = new Blend(BlendMode.SRC_OVER); blend.setBottomInput(new ColorInput(0, 0, totalWidth, totalHeight, color)); group.setEffect(blend); SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); WritableImage newImage = group.snapshot(parameters, null); return newImage; } catch (Exception e) { logger.error(e.toString()); return image; } }
Example 14
Source File: ListImageCell.java From MyBox with Apache License 2.0 | 4 votes |
private void init() { view = new ImageView(); view.setPreserveRatio(true); view.setFitHeight(height); }
Example 15
Source File: ScriptsDialog.java From phoebus with Eclipse Public License 1.0 | 4 votes |
private ImageView getScriptImage(ScriptItem item) { ImageView imageView = null; if (item != null) { final ScriptInfo info = item.getScriptInfo(); if (info != null) { final String path = info.getPath(); if (ScriptInfo.isEmbedded(path)) { if (ScriptInfo.isJavaScript(path)) imageView = JFXUtil.getIcon("javascript.png"); else if (ScriptInfo.isJython(path)) imageView = JFXUtil.getIcon("python.png"); else // It should never happen. imageView = JFXUtil.getIcon("unknown.png"); } else { if (ScriptInfo.isJavaScript(path)) imageView = JFXUtil.getIcon("file-javascript.png"); else if (ScriptInfo.isJython(path)) imageView = JFXUtil.getIcon("file-python.png"); else // It should never happen. imageView = JFXUtil.getIcon("file-unknown.png"); } } } if (imageView != null) { imageView.setPreserveRatio(true); imageView.setSmooth(true); } return imageView; }
Example 16
Source File: Main.java From mars-sim with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Callouts"); Pane root = new Pane(); int maxWidth = 1024; primaryStage.setScene(new Scene(root, maxWidth, 760)); primaryStage.setMaxWidth(maxWidth); primaryStage.setMinWidth(maxWidth); Image image = new Image(this.getClass().getResource(IMG).toExternalForm(), true); ImageView imageView = new ImageView(image); imageView.setPreserveRatio(true); imageView.fitWidthProperty().bind(primaryStage.widthProperty()); Callout callout1 = CalloutBuilder.create() .headPoint(600, 550) .leaderLineToPoint(400, 300) .endLeaderLineLeft() .mainTitle("STONEY CREEK") .subTitle("Pasadena, MD") .pause(5000) .build(); Callout callout2 = CalloutBuilder.create() .headPoint(200, 550) .leaderLineToPoint(400, 350.5) .endLeaderLineRight() .mainTitle("STONEY CREEK") .subTitle("Pasadena, MD") .pause(5000) .build(); Callout callout3 = CalloutBuilder.create() .headPoint(498, 186) .leaderLineToPoint(375, 406) .endLeaderLineLeft() .mainTitle("BLUE SKY") .subTitle("October 2017") .pause(5000) .build(); Callout callout4 = CalloutBuilder.create() .headPoint(667, 400) .leaderLineToPoint(778, 576) .endLeaderLineRight() .mainTitle("BOATS") .subTitle("On Lift") .pause(5000) .build(); root.getChildren().add(imageView); root.getChildren().addAll(callout1, callout2, callout3, callout4); // Animate 1-4 callouts to point out things in the picture EventHandler<KeyEvent> calloutKeyHandler = keyEvent -> { switch (keyEvent.getCharacter()) { case "1": callout1.play(); break; case "2": callout2.play(); break; case "3": callout3.play(); break; case "4": callout4.play(); break; default: callout1.play(); } }; root.addEventHandler(KeyEvent.KEY_TYPED, calloutKeyHandler); root.requestFocus(); // Observe mouse clicked coordinates root.setOnMouseClicked(mouseevent -> { System.out.println(mouseevent); }); primaryStage.show(); }
Example 17
Source File: IconEditorFactory.java From constellation with Apache License 2.0 | 4 votes |
@Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item != null) { final GridPane gridPane = new GridPane(); gridPane.setHgap(0); gridPane.setAlignment(Pos.TOP_LEFT); // icon final ConstellationIcon icon = IconManager.getIcon(item); final Image iconImage = icon.buildImage(); final ImageView imageView = new ImageView(iconImage); imageView.setPreserveRatio(true); imageView.setFitHeight(RECT_SIZE); final ColumnConstraints titleConstraint = new ColumnConstraints(RECT_SIZE); titleConstraint.setHalignment(HPos.CENTER); gridPane.getColumnConstraints().addAll(titleConstraint); gridPane.add(imageView, 0, 0); // dimension text if (iconImage != null) { final int width = (int) (iconImage.getWidth()); final int height = (int) (iconImage.getHeight()); final Text dimensionText = new Text(String.format("(%dx%d)", width, height)); dimensionText.setFill(Color.web("#d3d3d3")); gridPane.add(dimensionText, 0, 1); } // icon name final String displayableItem = icon.getExtendedName(); final String[] splitItem = displayableItem.split("\\."); String iconName = splitItem[splitItem.length - 1]; if (iconName.isEmpty()) { iconName = "(no icon)"; } this.setText(iconName); // tooltip final Tooltip tt = new Tooltip(item); this.setTooltip(tt); this.setGraphic(gridPane); this.setPrefHeight(RECT_SIZE + SPACING); } else { this.setText(null); this.setGraphic(null); } }
Example 18
Source File: Main.java From strangefx with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void start(Stage stage) throws Exception { LocalSimulator sim = new LocalSimulator(); QubitBoard board = new QubitBoard(2); HBox toolbarFiller = new HBox(); HBox.setHgrow( toolbarFiller, Priority.ALWAYS); ImageView logo = new ImageView("/Gluon_combined_logo_300px.png"); logo.setPreserveRatio(true); logo.setFitWidth(100); ToolBar toolbar = new ToolBar( createButton( "Append Qubit", e -> board.appendQubit() ), createButton( "Clear All", e -> board.clear() ), new Separator(), GateSymbol.of(new Identity(0), false), GateSymbol.of(new X(0), false), GateSymbol.of(new Y(0), false), GateSymbol.of(new Z(0), false), GateSymbol.of(new Hadamard(0), false), toolbarFiller, logo ); Model.getInstance().refreshRequest().set(true); ScrollPane scroller = new ScrollPane(board); scroller.setPannable(true); scroller.setFitToWidth(true); BorderPane borderPane = new BorderPane(); borderPane.setTop(toolbar); borderPane.setCenter(scroller); Scene scene = new Scene(borderPane, 800, 600); scene.getStylesheets().add(Main.class.getResource("/styles.css").toExternalForm()); stage.setScene(scene); stage.show(); }
Example 19
Source File: ListImageNameCell.java From MyBox with Apache License 2.0 | 4 votes |
private void init() { view = new ImageView(); view.setPreserveRatio(true); view.setFitHeight(height); }
Example 20
Source File: OtherEffects.java From Learn-Java-12-Programming with MIT License | 4 votes |
public void start(Stage primaryStage) { try { Text txt = new Text(); FileInputStream inputP = new FileInputStream("src/main/resources/packt.png"); Image imageP = new Image(inputP); ImageView ivP = new ImageView(imageP); FileInputStream inputM = new FileInputStream("src/main/resources/mount.jpeg"); Image imageM = new Image(inputM); ImageView ivM = new ImageView(imageM); ivM.setPreserveRatio(true); ivM.setFitWidth(300); EffectsThread et = new EffectsThread(txt, ivM, ivP); Button btnP = new Button("Pause"); btnP.setOnAction(e1 -> et.pause()); btnP.setStyle("-fx-background-color: lightpink;"); Button btnC = new Button("Continue"); btnC.setOnAction(e2 -> et.cont()); btnC.setStyle("-fx-background-color: lightgreen;"); GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setVgap(25); grid.setPadding(new Insets(10, 10, 10, 10)); int i = 0; grid.add(txt, 0, i++, 2, 1); GridPane.setHalignment(txt, HPos.CENTER); grid.add(ivP, 0, i++, 2, 1); GridPane.setHalignment(ivP, HPos.CENTER); grid.add(ivM, 0, i++, 2, 1); GridPane.setHalignment(ivM, HPos.CENTER); grid.addRow(i++, new Text()); HBox hb = new HBox(btnP, btnC); hb.setAlignment(Pos.CENTER); hb.setSpacing(25); grid.add(hb, 0, i++, 2, 1); GridPane.setHalignment(hb, HPos.CENTER); Scene scene = new Scene(grid, 450, 500); primaryStage.setScene(scene); primaryStage.setTitle("JavaFX effect demo"); primaryStage.onCloseRequestProperty() .setValue(e3 -> System.out.println("Bye! See you later!")); primaryStage.show(); et.start(); } catch (Exception ex){ ex.printStackTrace(); } }