当前位置: 首页>>代码示例>>Java>>正文


Java ImageView.setPreserveRatio方法代码示例

本文整理汇总了Java中javafx.scene.image.ImageView.setPreserveRatio方法的典型用法代码示例。如果您正苦于以下问题:Java ImageView.setPreserveRatio方法的具体用法?Java ImageView.setPreserveRatio怎么用?Java ImageView.setPreserveRatio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.scene.image.ImageView的用法示例。


在下文中一共展示了ImageView.setPreserveRatio方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createGameFileChooserButton

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private Button createGameFileChooserButton() {
		Button button = new Button();
		Image image = new Image(NEW_GAME);
		ImageView imageView = new ImageView(image);
		imageView.setFitWidth(App.WIDTH / 3);
		imageView.setPreserveRatio(true);
		button.setGraphic(imageView);
		//button.setWrapText(true);
		button.setOnMouseClicked((e) -> {
			FileLoader fileLoader = new FileLoader(primaryStage);
			File fileChosen = fileLoader.chooseFile();
			if (fileChosen != null) {
				startGame(fileChosen);
			}
		});
//		getRotation(button);
		return button;
	}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:19,代码来源:GameChooser.java

示例2: initSystemSettings

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private HBox initSystemSettings() {
	HBox settingBox = new HBox();
	settingBox.setAlignment(Pos.TOP_RIGHT);
	settingBox.setSpacing(15);

	Button musicButton = new Button();
	ImageView musicImageView = new ImageView(
			new Image(getClass().getClassLoader().getResourceAsStream(myResources.getString("music"))));
	musicImageView.setFitWidth(20);
	musicImageView.setPreserveRatio(true);
	musicButton.setGraphic(musicImageView);
	musicButton.setOnMousePressed(e -> {
		// TODO show a menu of several choices of background music
		System.out.println("Here should be a menu of background music choices.");
	});
	settingBox.getChildren().add(musicButton);
	return settingBox;
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:19,代码来源:GameManager.java

示例3: ReflectionSample

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
public ReflectionSample() {
    super(100,200);
    ImageView sample = new ImageView(BOAT);
    sample.setPreserveRatio(true);
    sample.setFitHeight(100);
    final Reflection reflection = new Reflection();
    sample.setEffect(reflection);
    getChildren().add(sample);
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Reflection Bottom Opacity", reflection.bottomOpacityProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Top Opacity", reflection.topOpacityProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Fraction", reflection.fractionProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Reflection Top Offset", reflection.topOffsetProperty(), -10d, 10d)
    );
    // END REMOVE ME
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:ReflectionSample.java

示例4: retriveImageFromFileAndFitToBox

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private void retriveImageFromFileAndFitToBox(final VBox vboxPhotoList, final File singleFileFromOpenedDialog) {
    LOGGER.info("Open image: ", singleFileFromOpenedDialog.toURI().getPath());
    BufferedImage bufferedImage = null;
    try {
        bufferedImage = ImageIO.read(singleFileFromOpenedDialog);
    } catch (IOException e) {
        e.printStackTrace();
    }
    final Image image = SwingFXUtils.toFXImage(bufferedImage, null);
    final ImageView imageView = new ImageView(image);
    vboxPhotoList.getChildren().clear();
    vboxPhotoList.getChildren().add(imageView);
    vboxPhotoList.setAlignment(Pos.CENTER);
    imageView.setPreserveRatio(true);
    if (imageView.getImage().getHeight() > vboxPhotoList.getHeight() ||
            imageView.getImage().getWidth() > vboxPhotoList.getWidth()) {
        imageView.fitHeightProperty().bind(vboxPhotoList.heightProperty());
        imageView.fitWidthProperty().bind(vboxPhotoList.widthProperty());
    }
    LOGGER.info("Image opened");

}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:23,代码来源:ImageViewController.java

示例5: start

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
    ImageView demo1Button = new ImageView();
    ImageView demo2Button = new ImageView();

    demo1Button.setFitWidth(200);
    demo2Button.setFitWidth(200);

    demo1Button.setPreserveRatio(true);
    demo2Button.setPreserveRatio(true);

    HBox.setHgrow(demo1Button, Priority.ALWAYS);
    HBox.setHgrow(demo2Button, Priority.ALWAYS);


    demo1Button.getStyleClass().add("demo1");
    demo2Button.getStyleClass().add("demo2");

    demo1Button.setOnMouseClicked(evt -> showDemo1());
    demo2Button.setOnMouseClicked(evt -> showDemo2());

    HBox container = new HBox(demo1Button, demo2Button);

    Scene scene = new Scene(container);
    scene.getStylesheets().add(MovieApp.class.getResource("/chooser.css").toExternalForm());
    scene.getStylesheets().add(MovieApp.class.getResource("/fonts.css").toExternalForm());

    primaryStage.setResizable(false);
    primaryStage.setTitle("Extreme GUI Makeover");
    primaryStage.setScene(scene);
    primaryStage.sizeToScene();
    primaryStage.setX(50);
    primaryStage.setY(100);
    primaryStage.show();
}
 
开发者ID:hendrikebbers,项目名称:ExtremeGuiMakeover,代码行数:36,代码来源:MovieApp.java

示例6: initialize

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private void initialize() {
    imageView = new ImageView();
    imageView.setPreserveRatio(true);
    imageView.setSmooth(true);
    imageView.setCache(true);

    imageViewExt = new ImageViewExt(imageView);

    BorderPane root = new BorderPane(imageView);
    imageView.fitWidthProperty().bind(widthProperty());
    imageView.fitHeightProperty().bind(heightProperty());

    Scene scene = new Scene(root);
    scene.setFill(Color.BLACK);
    setScene(scene);
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:17,代码来源:ImageStage.java

示例7: ImagePropertiesSample

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
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);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:39,代码来源:ImagePropertiesSample.java

示例8: ExtendedAnimatedFlowContainer

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
/**
 * Creates a container with the given animation type and duration.
 *
 * @param duration          the duration of the animation
 * @param animationProducer the {@link KeyFrame} instances that define the animation
 */
public ExtendedAnimatedFlowContainer(Duration duration, Function<AnimatedFlowContainer, List<KeyFrame>>
    animationProducer) {
    this.view = new StackPane();
    this.duration = duration;
    this.animationProducer = animationProducer;
    placeholder = new ImageView();
    placeholder.setPreserveRatio(true);
    placeholder.setSmooth(true);
}
 
开发者ID:b3log,项目名称:JHosts,代码行数:16,代码来源:ExtendedAnimatedFlowContainer.java

示例9: updateItem

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
@Override 
protected void updateItem(Book item, boolean empty) 
{
    // required to ensure that cell displays properly
   super.updateItem(item, empty);

   if (empty || item == null)
   {
      setGraphic(null); // don't display anything
   }
   else 
   {
      // create layout for cell
      VBox vbox = new VBox(8.0); // 8 points of gap between controls
      vbox.setAlignment(Pos.CENTER); // center contents horizontally
      
      // configure thumbnail image
      ImageView thumbImageView = 
         new ImageView(new Image(item.getThumbImage()));
      thumbImageView.setPreserveRatio(true);
      thumbImageView.setFitHeight(100.0); // thumbnail 100 points tall
      vbox.getChildren().add(thumbImageView); // attach to Vbox
      
      // configure text
      Label label = new Label(item.getTitle());
      label.setWrapText(true); // wrap if text too wide to fit in cell
      label.setTextAlignment(TextAlignment.CENTER); // center text
      vbox.getChildren().add(label); // attach to VBox
      
      setGraphic(vbox); // attach custom layout to ListView cell
      setPrefWidth(USE_PREF_SIZE); // use preferred size for cell width
   }
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:34,代码来源:ImageTextCell.java

示例10: openImage

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private void openImage() {
    Stage imagStage = new Stage();
    Pane pane = new Pane();
    ImageView iView = new ImageView(img);
    pane.getChildren().add(iView);
    iView.setLayoutX(0);
    iView.setLayoutY(0);
    iView.fitWidthProperty().bind(pane.widthProperty());
    iView.fitHeightProperty().bind(pane.heightProperty());
    iView.setPreserveRatio(true);
    Scene scene = new Scene(pane, 800, 800);
    imagStage.setTitle("" + img);
    imagStage.setScene(scene);
    imagStage.show();
}
 
开发者ID:maximstewart,项目名称:UDE,代码行数:16,代码来源:Icon.java

示例11: buildItemCell

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private Node buildItemCell(SocialMediaItem item) {
    HBox hbox = new HBox();
    InputStream resource = item.getClass().getResourceAsStream("icon.png");
    if (resource != null) {
        ImageView sourceImage = new ImageView();
        sourceImage.setFitHeight(18);
        sourceImage.setPreserveRatio(true);
        sourceImage.setSmooth(true);
        sourceImage.setCache(true);
        sourceImage.setImage(new Image(resource));
        hbox.getChildren().add(sourceImage);
    }

    if (item.getImage() != null) {
        HBox picture = new HBox();
        picture.setPadding(new Insets(0, 10, 0, 0));
        ImageView imageView = new ImageView(item.getImage());
        imageView.setPreserveRatio(true);
        imageView.setFitWidth(150);
        picture.getChildren().add(imageView);
        hbox.getChildren().add(picture);
    }

    Label text = new Label(item.getBody());
    text.setFont(Font.font(null, 20));
    text.setWrapText(true);
    hbox.getChildren().add(text);

    return hbox;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:31,代码来源:SocialMediaItemViewCell.java

示例12: createStretchingImagePane

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
public static StackPane createStretchingImagePane(final String image, final Scene scene)
{
	// the amount of work required to emulate the GinENGINE background scaler was quite excessive :/

	final ImageView backgroundImageView = new ImageView(JavaFxHelper.buildResourcePath(image));
	final double bgWidth = backgroundImageView.getImage().getWidth();
	final double bgHeight = backgroundImageView.getImage().getHeight();
	final SimpleDoubleProperty scaledWidth = new SimpleDoubleProperty();
	final SimpleDoubleProperty scaledHeight = new SimpleDoubleProperty();
	ChangeListener<? super Number> chl = new ChangeListener<Number>()
	{
		@Override
		public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue)
		{
			double scalingFactor = Math.max((scene.widthProperty().get() / bgWidth), (scene.heightProperty().get() / bgHeight));
			scaledWidth.set(bgWidth * scalingFactor);
			scaledHeight.set(bgHeight * scalingFactor);
		}
	};
	scene.widthProperty().addListener(chl);
	scene.heightProperty().addListener(chl);
	chl.changed(null, null, null);
	backgroundImageView.setPreserveRatio(true);
	backgroundImageView.fitWidthProperty().bind(scaledWidth);
	backgroundImageView.fitHeightProperty().bind(scaledHeight);
	StackPane backgroundImageStack = new StackPane();
	backgroundImageStack.getChildren().add(backgroundImageView);
	return backgroundImageStack;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:30,代码来源:JavaFxHelper.java

示例13: createFailureBox

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private StackPane createFailureBox( ) {
    final StackPane pane = new StackPane( );
    final ImageView background = new ImageView( UIUtils.createImage( "icons/square-red.png" ) );
    background.setPreserveRatio( true );
    background.setFitHeight( 70 );

    final Label label = new Label( );
    label.setFont( UIUtils.font( 32, FontWeight.BOLD ) );
    label.setTextFill( Color.WHITE );
    label.setEffect( UIUtils.shadowEffect( ) );
    label.textProperty( ).bind( _model.failureCountProperty( ).asString( ) );
    pane.getChildren( ).addAll( background, label );
    return pane;
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:15,代码来源:ProjectTileView.java

示例14: createLastBuildInfoBox

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private HBox createLastBuildInfoBox( final TileViewModel build ) {
    final HBox lastBuildInfoPart = new HBox( );
    lastBuildInfoPart.setAlignment( Pos.CENTER );

    final ImageView lastBuildIcon = new ImageView( UIUtils.createImage( "icons/lastBuild.png" ) );
    lastBuildIcon.setPreserveRatio( true );
    lastBuildIcon.setFitWidth( 32 );

    final Label lastBuildDate = new Label( );
    lastBuildDate.setMinWidth( 110 );
    lastBuildDate.setTextAlignment( CENTER );
    lastBuildDate.setAlignment( Pos.CENTER );
    lastBuildDate.setFont( UIUtils.font( 32, FontWeight.BOLD ) );
    lastBuildDate.setTextFill( Color.WHITE );
    lastBuildDate.setWrapText( true );
    lastBuildDate.setLineSpacing( 2 );  // TODO: Seems do not work
    lastBuildDate.setEffect( UIUtils.shadowEffect( ) );
    lastBuildDate.textProperty( ).bind( createStringBinding( ( ) -> {
        final LocalDateTime localDateTime = build.lastFinishedDateProperty( ).get( );
        if ( localDateTime == null )
            return "00/00\n00:00";
        return localDateTime.format( DateTimeFormatter.ofPattern( "dd/MM\nHH:mm" ) );
    }, build.lastFinishedDateProperty( ) ) );

    lastBuildInfoPart.getChildren( ).addAll( lastBuildIcon, lastBuildDate );
    return lastBuildInfoPart;
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:28,代码来源:TileView.java

示例15: addImageToGrid

import javafx.scene.image.ImageView; //导入方法依赖的package包/类
private ImageView addImageToGrid(String path) {
    ImageView imageView = imageViewFactory.create(path);
    imageView.fitHeightProperty().bind(imagesHeight);
    imageView.setPreserveRatio(true);
    images().add(imageView);
    return imageView;
}
 
开发者ID:AntonioGabrielAndrade,项目名称:LIRE-Lab,代码行数:8,代码来源:ImageGrid.java


注:本文中的javafx.scene.image.ImageView.setPreserveRatio方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。