I have this part of my code. I have a JLabel and a JButton that are in a panel. The I place that panel into another panel that has a border layout and I set the panel containing the label and button to be "NORTH", but the JLabel does not show. When I romove the button it does. Why? How can I fix this? Thanks. Here is my code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ISU implements ActionListener{
JFrame mainFrame;
JLabel descriptionLabel;
public JLabel pictureLabel;
JButton launchApplication;
public ISU (){
mainFrame = new JFrame ("Physics ISU Library");
JPanel mainPane = new JPanel ();
JPanel descriptPane = new JPanel ();
JPanel picPane = new JPanel ();
pictureLabel = new JLabel ();
JMenuBar menuBar = new JMenuBar ();
JMenu motionItem = new JMenu ("Motion");
JMenu energyItem = new JMenu ("Energy");
JMenu soundItem = new JMenu ("Sound");
JMenuItem transverseWave = new JMenuItem ("Transverse Wave"); transverseWave.setActionCommand("transverseWave");transverseWave.addActionListener(this);
JMenuItem longitudinalWave = new JMenuItem ("Longitudinal Wave"); longitudinalWave.setActionCommand("longitudinalWave"); longitudinalWave.addActionListener (this);
JMenuItem dopplerEffect = new JMenuItem ("Doppler Effect"); dopplerEffect.setActionCommand("dopplerEffect"); dopplerEffect.addActionListener(this);
JMenu electricityItem = new JMenu ("Electricity");
JMenu magnetismItem = new JMenu ("Magnetism");
soundItem.add(transverseWave); soundItem.add(longitudinalWave); soundItem.add(dopplerEffect);
menuBar.add(motionItem); menuBar.add(energyItem); menuBar.add(soundItem); menuBar.add(electricityItem); menuBar.add(magnetismItem);
mainFrame.add("North",menuBar);
descriptPane.setLayout (new BorderLayout ());
descriptionLabel = new JLabel ("This is the program that demonstrates how a blank works.");
launchApplication = new JButton ("Launch");
descriptPane.add(descriptionLabel);
descriptPane.add (launchApplication);
mainPane.setLayout(new BorderLayout ());
mainPane.add (descriptPane, BorderLayout.NORTH);
mainPane.add(picPane, BorderLayout.CENTER);
mainFrame.add (mainPane);
mainFrame.setSize (600,500);
mainFrame.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ISU isu = new ISU ();
}
}