Working on an assignment right now and I'm essentially writing my first GUI. Everything is working fine except my scrollbar- upon adding it not only will it not display, but even after I've commented it out, the LAST element added(via .add function call) covers the ENTIRE GUI. Setting the layout to null seemed to fix that, but I'm not sure if that will help or hinder the first issue. I've been through Oracle's documentation and examples already, and didn't see what I needed. Here is the pertinent code(variables a-g that seem to be floating in space are part of a separate section and I haven't pasted it so as to isolate the GUI code):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Example
{
public static void main(String[] args)
{
JFrame mygui = new JFrame();
mygui.getContentPane();
mygui.setBounds(100, 100, 700, 500);
mygui.setLayout(new BorderLayout()); //playing with layout here
JLabel first = new JLabel("integer:");
JLabel second = new JLabel("float:");
JLabel third = new JLabel("short:");
JLabel fourth = new JLabel("long:");
JLabel fifth = new JLabel("byte:");
JLabel sixth = new JLabel("double:");
JLabel seventh = new JLabel("boolean:");
JTextField myint = new JTextField("" + a);
JTextField myfloat = new JTextField("" + b);
JTextField myshort = new JTextField("" + c);
JTextField mylong = new JTextField("" + d);
JTextField mybyte = new JTextField("" + e);
JTextField mydbl = new JTextField("" + f);
JTextField mybool = new JTextField("" + g);
JTextArea myarea = new JTextArea();
JScrollPane scrolla = new JScrollPane(myarea);
first.setOpaque(true);
first.setBounds(20, 20, 50, 20);
second.setOpaque(true);
second.setBounds(20, 70, 50, 20);
third.setOpaque(true);
third.setBounds(20, 120, 50, 20);
fourth.setOpaque(true);
fourth.setBounds(20, 170, 50, 20);
fifth.setOpaque(true);
fifth.setBounds(20, 220, 50, 20);
sixth.setOpaque(true);
sixth.setBounds(20, 270, 50, 20);
seventh.setOpaque(true);
seventh.setBounds(20, 320, 50, 20);
myint.setBounds(70, 20, 50, 20);
myint.setOpaque(true);
myfloat.setBounds(70, 70, 50, 20);
myfloat.setOpaque(true);
myshort.setBounds(70, 120, 50, 20);
myshort.setOpaque(true);
mylong.setBounds(70, 170, 80, 20);
mylong.setOpaque(true);
mybyte.setBounds(70, 220, 50, 20);
mybyte.setOpaque(true);
mydbl.setBounds(70, 270, 50, 20);
mydbl.setOpaque(true);
mybool.setBounds(70, 320, 50, 20);
mybool.setOpaque(true);
myarea.setBounds(200, 50, 250, 200);
myarea.setOpaque(true);
scrolla.setPreferredSize(new Dimension(250, 200));
mygui.add(first);
mygui.add(second);
mygui.add(third);
mygui.add(fourth);
mygui.add(fifth);
mygui.add(sixth);
mygui.add(seventh);
mygui.add(myint);
mygui.add(myfloat);
mygui.add(myshort);
mygui.add(mylong);
mygui.add(mybyte);
mygui.add(mydbl);
mygui.add(mybool);
mygui.add(scrolla);
myarea.append("" + errcheck + "\n");
myarea.append("" + valcheck + "\n");
while(y < 2)
{
myarea.append("" + a + "\n");
myarea.append("" + b + "\n");
myarea.append("" + c + "\n");
myarea.append("" + d + "\n");
myarea.append("" + e + "\n");
myarea.append("" + f + "\n");
myarea.append("" + g + "\n");
myarea.append("" + w + "\n");
myarea.append("" + u + "\n");
myarea.append("" + v + "\n");
myarea.append("" + secondary + "\n");
myarea.append("" + whilecount + "\n");;
y++;
a--;
}
mygui.setVisible(true);
mygui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
I'm sure it's something simple but any feedback is appreciated.