0

i have project for category and subcategory i'm using gridpane for showing the category but i have small issue when i press next or previous i need just give limit view for example 5 category then when i press next or previous give me 5 category now is give me when i press next/previous sometime 6 sometime 3 sometime 5

database table in mysql :

CREATE TABLE mr_groupshow (
gr_srn INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
gr_name1 VARCHAR(30) NOT NULL,
gr_name2 VARCHAR(30) NOT NULL,
gr_status boolean,
gr_create_date TIMESTAMP
)

this is my FXML Code :

<AnchorPane fx:id="anchor_groups" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="95.0" prefWidth="331.0" style="-fx-background-color: #0d6d7c; -fx-border-color: #0d6d7c;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="285.0">
                     <children>
                        <GridPane fx:id="grid_groups" alignment="CENTER" gridLinesVisible="true" hgap="1.0" layoutX="44.0" maxHeight="-Infinity" prefHeight="96.0" style="-fx-background-color: b9e4e0;" styleClass="my-grid-groups" stylesheets="@mainmenu.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="43.0" AnchorPane.rightAnchor="44.0" AnchorPane.topAnchor="0.0">
                           <columnConstraints>
                              <ColumnConstraints halignment="CENTER" hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
                           </columnConstraints>
                           <rowConstraints>
                              <RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="ALWAYS" />
                           </rowConstraints>
                        </GridPane>
                        <HBox layoutX="45.0" layoutY="6.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" visible="false" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="44.0" AnchorPane.rightAnchor="44.0" AnchorPane.topAnchor="1.0" />
                        <Button fx:id="next_g" focusTraversable="false" layoutX="484.0" layoutY="2.0" mnemonicParsing="false" prefHeight="98.0" prefWidth="43.0" style="-fx-background-color: #2a97a1;" styleClass="addBobOk" stylesheets="@mainmenu.css" text="N" textFill="WHITE" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                           <effect>
                              <DropShadow color="#0eb0f5" />
                           </effect>
                        </Button>
                        <Button fx:id="previous_g" focusTraversable="false" layoutY="2.0" mnemonicParsing="false" prefHeight="99.0" prefWidth="43.0" style="-fx-background-color: #2a97a1;" styleClass="addBobOk" stylesheets="@mainmenu.css" text="P" textFill="WHITE" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0">
                           <effect>
                              <DropShadow color="#0eb0f5" />
                           </effect>
                        </Button>
                     </children>
                  </AnchorPane>

and this is code for get data from mysql :

//connect DB to show groups in gridgroups
    public int groupsview(int nw1, int pw1) {

        int row = 0;
        int col = 0;
        grid_groups.getChildren().clear();

        try {

            // Statement
            myStmt = con.createStatement();
            // SQL query
            rs = myStmt.executeQuery("SELECT * from mr_groupshow where gr_status=0 limit " + nw1 + "," + pw1 + "");
            // Result processing

            while (rs.next()) {
//                String itm = rs.getString("it.itemname_1");
                String grno = rs.getString("gr_srn");
                String grp = rs.getString("gr_name2");
                String img = rs.getString("gr_image");
                if (col > 4) {
                    row++;
                    col = 0;
                }
                imageviewgroups(col, row, img);
                gr_groups(col, row, grp);
                gr_groups_id(col, row, grno);
                col++;

            }
            System.out.println(myStmt);
            //End of Code
            //}
        } catch (FileNotFoundException | SQLException exc) {
            System.out.println(exc);
        }

        return pw1;

    }

and count for get count category from database :

//group count from db
    public int groupcount1(int count) {
        count = 0;
        try {
            // Statement
            myStmt = con.createStatement();
            // SQL query
            rs = myStmt.executeQuery("SELECT * from mr_groupshow where gr_status = 0 ");
            rs.last();
            count = rs.getRow();
        } catch (SQLException e) {
        }

        return count;

    }

and code for press next/previous button :

public void nextprevous(){
     previous_g.setOnAction((ActionEvent e) -> {
                int nc = 0;
                int nc1 = groupcount1(nc++);
                r2 = r1;
                r2 = 0;
                if (r1++ > 0) {
                    grid_groups.getChildren().remove(r2, r1);
                    groupsview(r2, r1);
                }

            });
            next_g.setOnAction((ActionEvent e) -> {
                int nc = 0;
                int nc1 = groupcount1(nc);
                r1 = r2;
                r2 = r1;
                if (r2++ < nc1++) {
                    grid_groups.getChildren().remove(r1, r2);
                    groupsview(r1, r2);

                }

            });
}

this is picuter of my category in my project :

enter image description here

2
  • I am a bit unclear with your question. Can you rephrase your question. Commented Mar 3, 2019 at 21:08
  • hi dear @SaiDandem i think is clear question i need but fix limit when i click to next button or previous button Commented Mar 4, 2019 at 7:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.