如何在图像数量发生变化时自动更改滑块值?

时间:2018-04-23 19:52:06

标签: matlab matlab-guide

我有两组图片(import javafx.application.Application; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.Button; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; import java.util.Random; public class AligningPains extends Application { private static final int N_POINTS = 5; private static final int MAX_POINT_POS = 100; private static final int POINT_RADIUS = 6; private static final int PREF_PANE_SIZE = 300; private static final int BUTTON_INSETS = 5; Point2D[] points = new Point2D[N_POINTS]; Random random = new Random(42); @Override public void start(Stage stage) { initPoints(); Pane pane = new Pane(); pane.setPrefSize(PREF_PANE_SIZE, PREF_PANE_SIZE); addCircles(pane, Color.GREEN); Pane smallPane = new Pane(); smallPane.setStyle("-fx-border-color: black;"); smallPane.setPrefSize(PREF_PANE_SIZE, PREF_PANE_SIZE); smallPane.setScaleX(0.25); smallPane.setScaleY(0.25); addCircles(smallPane, Color.RED); Group smallGroup = new Group(smallPane); Button startBtn = new Button("Start"); StackPane stackPane = new StackPane(pane, smallGroup, startBtn); StackPane.setAlignment(smallGroup, Pos.BOTTOM_LEFT); StackPane.setAlignment(startBtn, Pos.TOP_RIGHT); StackPane.setMargin(startBtn, new Insets(BUTTON_INSETS)); stackPane.setPrefSize(PREF_PANE_SIZE, PREF_PANE_SIZE); Scene scene = new Scene(stackPane); stage.setScene(scene); stage.show(); } private void addCircles(Pane pane, Color color) { for (Point2D sp : points) { Circle circle = new Circle(sp.getX(), sp.getY(), POINT_RADIUS, color); pane.getChildren().add(circle); } } private void initPoints() { for (int i = 0; i < points.length; i++) { points[i] = new Point2D(random.nextInt(MAX_POINT_POS), random.nextInt(MAX_POINT_POS)); } } public static void main(String[] args) { launch(args); } } ; set1: 100 images)。 最初,我使用set2: 25 images选择100张图片中的popupmenu,然后使用set1查看这些图片。 假设我的slider一分为slider value

现在,如果我使用56选择popupmenu的{​​{1}}。 set2

25 images

有没有办法根据我的as the slider value is 56 (> max: 25), the slider control is disappearing选项重置滑块。

我使用Warning: 'slider' control cannot have a 'Value' outside of 'Min'-'Max' range Control will not be rendered until all of its parameter values are valid popmenu转换为flag

popmenu selection

现在,当我使用get获取值时,它也大于25:

slider_callback

有什么建议吗?

由于

1 个答案:

答案 0 :(得分:0)

我能够弄清楚这一点,以防万一其他人有类似的问题:

value = int32(get(hObject,'Value'));
if value == 0 || maxNumberOfImages == 1 
    value = 1;
elseif value > maxNumberOfImages
    value = maxNumberOfImages;
end
disp(value);
set(handles.sliderC, 'Value', value);

如果该值大于maxNumberOfImages,我会再次将当前handle value设置为maxNumberOfImages,这会像我预期的那样重置滑块控件而不会禁用滑块。