Die Anleitung zu JavaFX ScrollPane

View more categories:

1- JavaFx ScrollPane

ScrollPane  ist ein rollbarer Teil von Schnittstelle (scrollable). Er wird benutzt, eine große Inhalt in einem begrenzten Raum anzuzeigen. Er hat die vertikalen und horizontalen Bildlaufsleite (scroll bar)

ScrollBar Policy

Sie können die Anzeige-Politik (scrollbar policy) für die Bildlaufleiste setzen
  • NEVER - Never display
  • ALWAYS - Always display
  • AS_NEEDED - Display if needed.
** ScrollBarPolicy **

// Setting a horizontal scroll bar is always display
scrollPane.setHbarPolicy(ScrollBarPolicy.ALWAYS);

// Setting vertical scroll bar is never displayed.
scrollPane.setVbarPolicy(ScrollBarPolicy.NEVER);

2- Das Beispiel über ScrollPane

ScrollPaneDemo1.java
package org.o7planning.javafx.scrollpane;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.stage.Stage;

public class ScrollPaneDemo1 extends Application {

    @Override
    public void start(Stage primaryStage) {

        // Create a ScrollPane
        ScrollPane scrollPane = new ScrollPane();

        Button button = new Button("My Button");
        button.setPrefSize(400, 300);

        // Set content for ScrollPane
        scrollPane.setContent(button);

        // Always show vertical scroll bar
        scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
       
        // Horizontal scroll bar is only displayed when needed
        scrollPane.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);

        primaryStage.setTitle("ScrollPane Demo 1 (o7planning.org)");
        Scene scene = new Scene(scrollPane, 550, 200);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Beispiel

3- Das Beispiel über ScrollPane und Pannable

ScrollPaneDemo2.java
package org.o7planning.javafx.scrollpane;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class ScrollPaneDemo2 extends Application {
   
    @Override
    public void start(Stage primaryStage) {
 
        final FlowPane container = new FlowPane();
       
        // Button 1
        Button button1= new Button("Button 1");
        button1.setPrefSize(350, 100);
       
        container.getChildren().add(button1);
       
        // Button 2
        Button button2= new Button("Button 2");
        button2.setPrefSize(245, 220);
       
        container.getChildren().add(button2);
     
        // ScrollPane
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setContent(container);
       
        // Pannable.
        scrollPane.setPannable(true);
     

        primaryStage.setTitle("ScrollPane Demo 2 (o7planning.org)");
        Scene scene = new Scene(scrollPane, 550, 200);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Beispiel

View more categories: