I'd like to add a scrollbar to a JPanel that uses Absolute Layout.
package Default;
import javax.swing.JFrame;
import javax.swing.border.EmptyBorder;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JScrollPane;
public class teste extends JFrame {
private JPanel contentPane;
public static void main(String[] args)
{
teste frame = new teste();
frame.setVisible(true);
}
private static int qtButton = 0 ;
public teste()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 500);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JScrollPane panel = new JScrollPane();
panel.setBounds(10, 11, 464, 439);
contentPane.add(panel);
for(int i = 0; i < 15; i++)
{
gerarButton(panel);
}
}
public static void gerarButton(JScrollPane panel)
{
JButton NewButton = new JButton("New button");
NewButton.setBounds(10, 11 + (34 * qtButton), 444, 23);
panel.add(NewButton);
qtButton ++;
panel.repaint();
}
}
And here's how it goes
HowcouldIdothis??
Note:thebuttonsinsideare"infinite"