Note that there are some explanatory texts on larger screens.

plurals
  1. POJScrollPane doesn't appear in my JTextArea
    text
    copied!<p>This class is the layout and implementation for the first tab in my program, the CreatePanel. I am trying to implement a JScrollPane in my JTextArea. However, the scroll bar never appears, although the program compiles correctly. I've looked all over for solutions and have tried a couple of variations, but nothing is seeming to work.</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class CreatePanel extends JPanel { private Vector flightList; private SelectPanel sPanel; private JButton createButton; private JLabel airName, flightNumber, departCity, departDay, departTime, arriveCity, arriveDay, arriveTime, price; private JLabel notify, blank; private JTextField l1, l2, l3, l4, l5, l6, l7, l8, l9; private JTextArea flightInfo; private JScrollPane scroll; String air, num, dC, dD, dT, aC, aD, aT, prc; //Constructor initializes components and organize them using certain layouts public CreatePanel(Vector flightList, SelectPanel sPanel) { this.flightList = flightList; this.sPanel = sPanel; // organize components here // creates all labels and textfields for Flight Creation tab notify = new JLabel(""); blank = new JLabel(""); airName = new JLabel("Enter a name of Airlines"); flightNumber = new JLabel("Enter a flight number"); departCity = new JLabel("Enter a departure city"); departDay = new JLabel("Enter a departure day"); departTime = new JLabel("Enter a departure time"); arriveCity = new JLabel("Enter an arrival city"); arriveDay = new JLabel("Enter an arrival day"); arriveTime = new JLabel("Enter an arrival time"); price = new JLabel("Price"); l1 = new JTextField(""); l2 = new JTextField(""); l3 = new JTextField(""); l4 = new JTextField(""); l5 = new JTextField(""); l6 = new JTextField(""); l7 = new JTextField(""); l8 = new JTextField(""); l9 = new JTextField(""); createButton = new JButton("Create a flight"); createButton.addActionListener(new ButtonListener()); flightInfo = new JTextArea("No flight"); flightInfo.setEditable(false); // the user-entered information panel JPanel panelUser = new JPanel(); panelUser.setLayout(new GridLayout(10, 2)); panelUser.add(notify); panelUser.add(blank); panelUser.add(airName); panelUser.add(l1); panelUser.add(flightNumber); panelUser.add(l2); panelUser.add(departCity); panelUser.add(l3); panelUser.add(departDay); panelUser.add(l4); panelUser.add(departTime); panelUser.add(l5); panelUser.add(arriveCity); panelUser.add(l6); panelUser.add(arriveDay); panelUser.add(l7); panelUser.add(arriveTime); panelUser.add(l8); panelUser.add(price); panelUser.add(l9); // panel for the button JPanel panelButton = new JPanel(); panelButton.add(createButton); // the leftside panel of CreatePanel JPanel panelLeft = new JPanel(); panelLeft.setLayout(new BorderLayout()); panelLeft.add(panelUser, BorderLayout.CENTER); panelLeft.add(panelButton, BorderLayout.SOUTH); // the rightside panel of CreatePanel JPanel panelInfo = new JPanel(); scroll = new JScrollPane(flightInfo); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scroll.setVisible(true); panelInfo.setLayout(new GridLayout(1, 1)); panelInfo.add(flightInfo); // WHY WONT YOU WORK? // layout for CreatePanel setLayout(new GridLayout(1, 2)); add(panelLeft); add(panelInfo); } } </code></pre> <p>What am I doing wrong when adding the JScrollPane??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload