I have a JFrame and i need to add panels to it where i like, but I am not sure how to do it. I have tried all the layouts but i cant get what i want.
Basically FunProgramming is the main frame and I need 3 other panels on that frame. i need one in the middle/right. i need a panel to the left and one across the bottom and about 1/3 up the frame. After trying the different layout managers I'm not sure how to go about doing this(also sorry, i couldn't seem to separate the two classes, the first one it now missing a {)
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class FunProgrammingFrame {
private JFrame frame;
private JMenuBar menuBar;
private JMenu menu;
private JMenuItem menuItem;
private final String M_ITEM_ONE = "File", M_ITEM_TWO = "Project", M_ITEM_THREE = "Help", ITEM_ONE = "New", ITEM_TWO = "Open", ITEM_THREE = "Save", ITEM_FOUR = "Quit";
public FunProgrammingFrame(){
ConsolePanel consolePanel = new ConsolePanel();
frame = new JFrame("Fun Programming");
frame.setLayout(new GridBagLayout());
//frame.add(consolePanel, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
menuBar = new JMenuBar();
createMenu(M_ITEM_ONE);
addMenuItem(ITEM_ONE);
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
});
addMenuItem(ITEM_TWO);
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
});
addMenuItem(ITEM_THREE);
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
});
menu.addSeparator();
addMenuItem(ITEM_FOUR);
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
createMenu(M_ITEM_TWO);
createMenu(M_ITEM_THREE);
//addPanel(consolePanel, 10, 10, GridBagConstraints.SOUTH);
frame.setVisible(true);
}
public void createMenu(String name){
menu = new JMenu(name);
menuBar.add(menu);
frame.setJMenuBar(menuBar);
}
public JMenuItem addMenuItem( String itemName) {
menuItem = new JMenuItem(itemName);
menu.add(menuItem);
return menuItem;
}
public static void main(String[] args){
FunProgrammingFrame fp = new FunProgrammingFrame();
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
public class ConsolePanel extends JPanel{
private JPanel Cpanel;
private final int WIDTH = 100, HEIGHT = 500;
public ConsolePanel(){
Cpanel = new JPanel(new BorderLayout());
Cpanel.setSize(WIDTH, HEIGHT);
Cpanel.setVisible(true);
setBackground(Color.BLACK);
}
}
Link to the what i need https://i.stack.imgur.com/9aibx.jpg the buttons to the side are not needed for now