ValueProperty method:
public final DoubleProperty valueProperty()This method is used to detect the current value represented by this Slider. This value must always be between minimum and maximum value.
CODING:
import javafx.application.Application;import javafx.scene.Scene;
import javafx.scene.control.Slider;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
public class mainfx extends Application
{
Slider slider = new Slider(175,500,250);
Slider slider1 = new Slider(150,300,150);
Label l1 = new Label("Width Of Image");
Label l2 = new Label("Height Of Image");
Image image = new Image ("face.jpg");
ImageView iv = new ImageView();
@Override
public void start(Stage primaryStage)
{
slider.setShowTickLabels(true);
slider1.setShowTickLabels(true);
iv.setFitHeight(150);
iv.setImage(image);
StackPane grid = new StackPane();
FlowPane flow = new FlowPane();
FlowPane flow1 = new FlowPane();
flow.getChildren().add(iv);
flow1.getChildren().addAll(l1,slider,l2,slider1);
flow1.setPrefWrapLength(110);
flow1.setVgap(20);
BorderPane border = new BorderPane();
border.setTop(flow);
border.setLeft(flow1);
Scene scene = new Scene(border, 600, 350,Color.WHITE);
primaryStage.setTitle("Slider In Javafx");
primaryStage.setScene(scene);
slider.valueProperty().addListener(new ChangeListener<Number>()
{
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldvalue, Number newvalue)
{
int ne = newvalue.intValue();
iv.setFitWidth(ne*4);
}
});
slider1.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldvalue, Number newvalue)
{
int ne1 = newvalue.intValue();
iv.setFitHeight(ne1);
}
});
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
import javafx.scene.control.Slider;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
public class mainfx extends Application
{
Slider slider = new Slider(175,500,250);
Slider slider1 = new Slider(150,300,150);
Label l1 = new Label("Width Of Image");
Label l2 = new Label("Height Of Image");
Image image = new Image ("face.jpg");
ImageView iv = new ImageView();
@Override
public void start(Stage primaryStage)
{
slider.setShowTickLabels(true);
slider1.setShowTickLabels(true);
iv.setFitHeight(150);
iv.setImage(image);
StackPane grid = new StackPane();
FlowPane flow = new FlowPane();
FlowPane flow1 = new FlowPane();
flow.getChildren().add(iv);
flow1.getChildren().addAll(l1,slider,l2,slider1);
flow1.setPrefWrapLength(110);
flow1.setVgap(20);
BorderPane border = new BorderPane();
border.setTop(flow);
border.setLeft(flow1);
Scene scene = new Scene(border, 600, 350,Color.WHITE);
primaryStage.setTitle("Slider In Javafx");
primaryStage.setScene(scene);
slider.valueProperty().addListener(new ChangeListener<Number>()
{
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldvalue, Number newvalue)
{
int ne = newvalue.intValue();
iv.setFitWidth(ne*4);
}
});
slider1.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldvalue, Number newvalue)
{
int ne1 = newvalue.intValue();
iv.setFitHeight(ne1);
}
});
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
No comments:
Post a Comment