Question: Java GUI From the code below, why I won't get scroll pane on the frame when I change private JPanel secondWindow() to private void secondWindow()?

Java GUI

From the code below, why I won't get scroll pane on the frame when I change private JPanel secondWindow()

to private void secondWindow()? I mean, I still can get buttons on the frame but not scroll pane.

package proj02; import javax.swing.*; import java.awt.*; public class AddressBookGUI { private JPanel window01; private JPanel window02; private JScrollPane scrollPanel; private JButton displayButton; private JButton newButton; private JButton removeButton; private JPanel box; public static void main(String args[]) { AddressBookGUI inst = new AddressBookGUI(); JFrame frame = new JFrame("Address Book"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(inst.windowBox()); frame.pack(); frame.setVisible(true); } private JPanel windowBox() { box = new JPanel(); box.setLayout(new BorderLayout()); box.add(firstWindow(), BorderLayout.CENTER); box.add(secondWindow(), BorderLayout.SOUTH); return box; } private JPanel firstWindow() { window01 = new JPanel(); scrollPanel = new JScrollPane(); scrollPanel.setPreferredSize(new Dimension(100,50)); scrollPanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); window01.add(scrollPanel, BorderLayout.NORTH); window01.setBounds(0, 0, 300, 150); return window01; } private JPanel secondWindow() { window02 = new JPanel(); displayButton = new JButton("Display"); newButton = new JButton("New"); removeButton = new JButton("Remove"); window02.add(displayButton); window02.add(newButton); window02.add(removeButton); window02.setBounds(0, 150, 300, 150); return window02; } } 
it is complete question

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!