This discussion is archived
3 Replies Latest reply: Feb 26, 2013 12:22 AM by 984080 RSS

How to create 99 rows in gridPane but 98 rows to be visible when needed?

tanvir ahmed Newbie
Currently Being Moderated
Hi Every Body?

Pls hekp me.

I want to create 99 rows in gridPane but 98 rows to be visible when needed?
  • 1. Re: How to create 99 rows in gridPane but 98 rows to be visible when needed?
    984080 Explorer
    Currently Being Moderated
    Hey,

    Please provide us some more info to be able to help you..


    - Do you mean a GridPane, or a Table?
    - Do you mean something like pagination on a table?
    - Do you mean using a vertical scrollbar? (set by default in a table)
    - When should your row be visible and when not?

    thx in advance!
  • 2. Re: How to create 99 rows in gridPane but 98 rows to be visible when needed?
    tanvir ahmed Newbie
    Currently Being Moderated
    yeh

    I want to create 99 rows in a gridPane not table with verticall scrollpane.

    Regards
  • 3. Re: How to create 99 rows in gridPane but 98 rows to be visible when needed?
    984080 Explorer
    Currently Being Moderated
    You will have to make some calculations.
    - height of gridpane
    - height for every row

    --> those values will be fixed!
    Else you need a resizable gridpane / rows, and this is more difficult to be sure if your rows are big enough to see the content!


    Here an fully working example with 29 rows who should be visible. (98 rows are a lot!, but it's the same pricipe with another amount of rows)
    package temp3;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.ScrollPane;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    
    public class Temp3 extends Application {
    
        @Override
        public void start(Stage primaryStage) {
            StackPane sp = new StackPane();
            sp.getChildren().add(show29Rows());
            Scene scene = new Scene(sp, 1024, 768, Color.BLACK);
    
            primaryStage.setTitle("29Rows");
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    
        /**
         * The main() method is ignored in correctly deployed JavaFX application.
         * main() serves only as fallback in case the application can not be
         * launched through deployment artifacts, e.g., in IDEs with limited FX
         * support. NetBeans ignores main().
         *
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            launch(args);
        }
    
        private ScrollPane show29Rows() {
            GridPane gp = new GridPane();
    
            ScrollPane s1 = new ScrollPane();
            s1.setStyle("-fx-background-color: white");
            s1.setPrefHeight(725); //we want 29 rows of 25px height = 725px
            s1.setMaxHeight(725);
            s1.setContent(gp);
    
            //example that we have 50 rows
            for (int i = 0; i < 50; i++) {
                Label lbl = new Label("value " + (i+1));
                lbl.setMinHeight(25);
                lbl.setMaxHeight(25);
                GridPane.setConstraints(lbl, 1, i);
                gp.getChildren().add(lbl);
            }
    
            return s1;
        }
    }
    Good luck!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points