adding Commonest to jPanel with gridLayout

20 Views Asked by At

so I am making a program to study and I want to see and edit the words that you upload in a Jscrollpane and I have a JPanel with gridlayout(0,2) in the Jscrollpane (with maximum height of 700) and when I start the program it adds buttons to the JPanel to see that it works. it works but when the Jscrollpane gets to big it does something strange it moves the Jscrollpane to under when buttons is to much(35 buttons) but when I have under 30 buttons it is normal 7 buttons I use GUI form in IntelliJ IDEA CE and this is how it looks in the form(I don't know that it has anything to do with it) GUI form

code: (does when you start program) public void setknoppen() { panel1.setVisible(false); //I have a menu and when you press a button it sets that panel to invisible and this to visible

    panel2.setLayout(new GridLayout(0, 2));

//panel2= panel in Jscrollpane

    for (int i = 0; i < 60; i++) {
        Button button = new Button("question" + i);
        panel2.add(button);
        button = new Button("anser" + i);
        panel2.add(button);
    }
    System.out.println(scrollpane.getY());
    panel1.revalidate();
    panel1.repaint();
}

I tried to revalidate and repaint the panel1, panel2, Jscrollpane. I tried tried to add the textfield (what I want in the end instead of the buttons) and the same happens

what I want is that the Jscrollpane is in the top of the Frame and if I want to scroll to see the one that you can't see I can. just like this (I made it in pages so it looks a bit strange) (the darker part on the right is the scroller) what i want

0

There are 0 best solutions below