Reputation: 133
I've been having trouble recreating this GUI:
We've been told to use the BorderLayout with grids inside each section. I've been trying to head the header to work (the top square of the GUI with the class name and person name), but I can't seem to get anything to show up. This is what I have so far:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Display extends JFrame implements ActionListener {
private static final int FRAME_WIDTH = 400;
private static final int FRAME_HEIGHT = 350;
private static final int FRAME_X_ORIGIN = 100;
private static final int FRAME_Y_ORIGIN = 75;
public static void main(String[] args) {
Display frame = new Display();
frame.setVisible(true);
}
public Display() {
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setLayout(null);
setTitle("CSCE155A Course Offering Viewer");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// header
JPanel header = new JPanel();
header.setLayout(new GridLayout(2, 1));
header.setSize(380, 50);
header.setLocation(0, 0);
header.setBorder(BorderFactory.createLineBorder(Color.BLACK));
header.add(new JLabel("CSCE155A Course Offering Viewer"));
header.add(new JLabel("First Last"));
}
public void actionPerformed(ActionEvent event) {
}
}
The only thing that shows up is the window with nothing inside it.
Upvotes: 0
Views: 2463
Reputation: 3833
I think you need to create a container-object where you can put your panels. Here I put two panels within a BorderLayout
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(inputPanel, BorderLayout.EAST);
contentPane.add(rightPanel, BorderLayout.CENTER);
Upvotes: 0
Reputation: 324088
We've been told to use the BorderLayout with grids inside each section
setLayout(null);
So why are you using a null layout on the frame?
Where do you add the panel to the frame?
You where given a link yesterday in your question: JPanels and GridLayouts to the Swing tutorial on How to Use a Border Layout. You where also given example code that showed you how to add the panel to the frame.
Read the tutorial, download the working example and then customize the example for your needs.
Don't keep repeating questions in the forum when you don't listen to previous advice!
Upvotes: 2