Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago