【问题标题】:How to add ScrollPane to main stage如何将 ScrollPane 添加到主舞台
【发布时间】:2013-06-05 12:41:58
【问题描述】:

我很感兴趣如何将ScrollPane 添加到主舞台。当我减小主页的大小时,我想使用ScrollPane 移动到主舞台上。有例子吗?

【问题讨论】:

    标签: javafx-2 javafx javafx-8


    【解决方案1】:

    如果ScrollPane 的内容大于ScrollPane 的允许大小,ScrollPane 应自动附加滚动条。这是一个例子:

    public class JFXScroll extends Application {
    
        @Override
        public void start(Stage stage) throws Exception {
    
            BorderPane main = new BorderPane();
    
            ScrollPane scroll = new ScrollPane();
            VBox box = new VBox();
    
            // Demo purposes; Wouldn't normally do this - just let the box automatically fit the content
            box.setPrefSize(1000, 500);
            box.setEffect(new ColorInput(0,0,1000,500,Color.LIME));
    
            scroll.setContent(box);
    
            main.setLeft(new Label("Left Content"));
            main.setCenter(scroll);
    
            Scene scene = new Scene(main, 300, 250);
            stage.setScene(scene);
            stage.show();
    
    
        }
        public static void main(String[] args) {
            launch(args);
        }
    }
    

    【讨论】:

      【解决方案2】:

      stage.setScene(new ScrollPane(yourContent)); 应该这样做。 当然,您的内容应该有适当的最小、最大和首选尺寸

      【讨论】:

        猜你喜欢
        • 2012-11-22
        • 1970-01-01
        • 2013-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-26
        • 2014-08-29
        相关资源
        最近更新 更多