Im trying to make a dynamic list of entries for a budget program. Initially there is supposed to be 10 items in this list and i want to give the user the option to add more items and have the panel scrollable. Every item is a panel that contains 1 label and 1 textbox.
My problem is i have the main panel's layout set to grid, and i have set the number of colums to 2 and the number of rows to 0, when adding an 11th item to this panel it creates a new row which is fine, except the panel's "view" widens when adding things to this panel.
I'd like to have the panel's "view" to stay the same size and be able to scroll down to see its other contents.
Heres my code:
private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
javax.swing.JPanel newCategoryPanel = new javax.swing.JPanel();
javax.swing.JLabel newLabel = new javax.swing.JLabel();
javax.swing.JTextField newTextField = new javax.swing.JTextField();
newCategoryPanel.setLayout(new java.awt.GridLayout(1, 2));
newLabel.setText("Poop :)"); //for testing
newCategoryPanel.add(newLabel);
newTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
newCategoryPanel.add(newTextField);
panel1.add(newCategoryPanel);
panel1.revalidate();
}