Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:48:34+00:00 2026-05-11T05:48:34+00:00

I’m trying to make a GUI in java, but JMenuBar has been giving me

  • 0

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();     }   } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:48:34+00:00Added an answer on May 11, 2026 at 5:48 am

    You have an awful lot of extra code there.

    public class SelectionFrame extends JFrame {     Font name;     Font title;      public SelectionFrame()     {         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setJMenuBar(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 void main( String args[] )     {          SelectionFrame sel = new SelectionFrame();         sel.setLocationRelativeTo(null);         sel.setSize(400 + (sel.getInsets().left + > sel.getInsets().right), 400         + (sel.getInsets().top + sel.getInsets().bottom));          sel.setTitle('Tiles/Meta');         sel.setResizable(false);         sel.setFocusable(true);          sel.getContentPane().add( new JLabel( 'Content', SwingConstants.CENTER),          BorderLayout.CENTER );         sel.setLocation(sel.getX() - (sel.getWidth() / 2), sel.getY() - >             (sel.getHeight() / 2));         sel.setVisible(true);      } } 

    That shows up with a menu bar and everything. if you add your content to the CENTER of the content pane (by default a border layout), the center automatically fills the whole content area, you don’t have to resize anything.

    This shows up as a window with a menu bar and everything works fine.

    What platform are you doing this on? I’m on Vista, i get what i expect to see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 81k
  • Answers 81k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is called a Soft 404 or False 404. Wikipedia… May 11, 2026 at 4:26 pm
  • Editorial Team
    Editorial Team added an answer To fix this I ended up downgrading. I was using… May 11, 2026 at 4:26 pm
  • Editorial Team
    Editorial Team added an answer No, select new will not trigger evaluation. This will map… May 11, 2026 at 4:26 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.