Here's the code I have for my GUI
public class gui extends JFrame{
JFrame mainF;
JPanel listPanel;
JTextArea jtArea;
ButtonGroup buttons;
ButtonGroup restoreButtons;
JRadioButton createButton;
JRadioButton saveButton;
JRadioButton deleteButton;
JRadioButton redo;
JRadioButton undo;
gui() {
this.mainF = new JFrame();
mainF.getContentPane().setBackground(Color.gray);
mainF.setLayout(null);
mainF.setSize(800, 800);
createButton = new JRadioButton("Create note");
createButton.setBounds(10, 150, 150, 50);
saveButton = new JRadioButton("Save note");
saveButton.setBounds(10, 250, 150, 50);
saveButton.setEnabled(false);
redo = new JRadioButton("Redo");
redo.setBounds(10, 400, 150, 50);
redo.setEnabled(false);
undo = new JRadioButton("Undo");
undo.setBounds(10, 350, 150, 50);
undo.setEnabled(false);
deleteButton = new JRadioButton("Delete note");
deleteButton.setBounds(10, 500, 150, 50);
deleteButton.setEnabled(false);
this.jtArea = new JTextArea();
int centerX = (mainF.getWidth() - 200) / 2;
int centerY = (mainF.getHeight() - 500) / 2;
jtArea.setBounds(centerX, centerY, 200, 500);
jtArea.setBackground(Color.white);
jtArea.setEnabled(false);
JScrollPane scrollPane = new JScrollPane(jtArea);
scrollPane.setBounds(centerX, centerY, 200, 500);
jtArea.setLineWrap(true);
jtArea.setWrapStyleWord(true);
jtArea.setEnabled(false);
this.listPanel = new JPanel(new GridLayout(0, 1));
JScrollPane listScrollPane = new JScrollPane(listPanel);
listScrollPane.setBounds(centerX + 285, centerY, 200, 500);
listScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
buttons = new ButtonGroup();
buttons.add(createButton);
buttons.add(saveButton);
buttons.add(deleteButton);
buttons.add(undo);
buttons.add(redo);
mainF.add(jtArea);
mainF.add(createButton);
mainF.add(saveButton);
mainF.add(deleteButton);
mainF.add(redo);
mainF.add(undo);
mainF.add(listScrollPane);
mainF.setVisible(true);
mainF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
I'm still unfamiliar with GUI components so this is very new to me. It shows a scroll bar on the right side, but I can't scroll through it when it's full. My entire code is supposed to add buttons to that listPanel and if it gets full then I can scroll through them but that doesn't seem to be the case.
mainF.setLayout(null);
is a bad idea - Laying Out Components Within a ContainerjtArea.setBounds(centerX, centerY, 200, 500);
this isn't helping you either. You're fixing the size of the JTextArea so that it cannot expand if need be.listPanel
? In posted code, it is empty, so there is nothing to scroll! You posted a lot of (irrelevant?) code but somehow the post is missing almost all code regardinglistPanel
(assuming that is the one not scorlling) - if I add enough buttons to it, I can scroll normally.