I'm trying to make a GUI in java, but JMenuBar has been giving me a hard time for two days. Can someone please tell me why it isn't showing up?
import java.awt.*;
import javax.swing.*;
import javax.swing.JPanel;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.Arrays;
import javax.imageio.ImageIO;
public class selectionFrame extends JFrame
{
Font name;
Font title;
public void setup() //can't use constructer because this isn't given a size until after it is constructed.
{
//getContentPane().add(menuBar);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());
//getContentPane().add(j);
setJMenuBar(createMenuBar());
//getContentPane().add(createMenuBar());
}
public JMenuBar createMenuBar()
{
JMenuBar menuBar;
JMenu m_file;
JMenuItem mi_save;
JMenuItem mi_load;
JMenu m_edit;
JMenuItem mi_tileHeight;
JMenuItem mi_tileWidth;
menuBar = new JMenuBar();
m_file = new JMenu("File");
m_edit = new JMenu("Edit");
mi_save = new JMenuItem("Save file", KeyEvent.VK_S);
mi_load = new JMenuItem("Load file", KeyEvent.VK_L);
mi_tileHeight = new JMenuItem("Set tile height", KeyEvent.VK_H);
mi_tileWidth = new JMenuItem("Set tile width", KeyEvent.VK_W);
menuBar.add(m_file);
m_file.add(mi_save);
m_file.add(mi_load);
menuBar.add(m_edit);
m_edit.add(mi_tileHeight);
m_edit.add(mi_tileWidth);
return menuBar;
}
public static void main(String[] args) //run
{
selectionFrame sel = new selectionFrame();
sel.setLocationRelativeTo(null);
sel.setSize((int) 400 + (sel.getInsets().left + sel.getInsets().right),(int) 400 + (sel.getInsets().top + sel.getInsets().bottom));
sel.setVisible(true);
sel.setTitle("Tiles/Meta");
sel.setResizable(false);
sel.setFocusable(true);
sel.getContentPane().setSize(sel.getSize());
sel.setLocation((int) sel.getX() - (sel.getWidth()/2),(int) sel.getY() - (sel.getHeight()/2));
sel.setup();
sel.repaint();
}
}