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

  • SEARCH
  • Home
  • 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 4614240
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:40:12+00:00 2026-05-22T01:40:12+00:00

I am trying to view a JApplet within a JFrame. Class: Paint public void

  • 0

I am trying to view a JApplet within a JFrame.

Class: Paint
public void paint(Graphics g) {
  g.drawString("hi", 50, 50);
}

public static void main(String args[]) {
  JFrame frame = new JFrame("test");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setJMenuBar(methodThatReturnsJMenuBar());

  JPanel panel = new JPanel(new BorderLayout());
  frame.add(panel);

  JApplet applet = new Paint();
  panel.add(applet, BorderLayout.CENTER);
  applet.init();
  frame.pack();

  frame.setVisible(true);
}

The applet shows up in the Window, but there is no background (it’s transparent), and when I click on the Menu, the list is covered. How do I make it so that the Menu list isn’t covered, and there is a background?

Edit: When I draw a white rectangle, it fixes the background problem, but the Menu list is still covered.

  • 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. Editorial Team
    Editorial Team
    2026-05-22T01:40:13+00:00Added an answer on May 22, 2026 at 1:40 am

    I would gear my GUI creation towards making a JPanel and then use the JPanel as I desire, either in an JApplet or a JFrame. For e.g.,

    import java.awt.*;
    import javax.swing.*;
    
    public class MyPanel extends JPanel {
       private static final Dimension PREF_SIZE = new Dimension(400, 300);
    
       @Override
       protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.drawString("hi", 50, 50);
       }
    
       @Override
       public Dimension getPreferredSize() {
          return PREF_SIZE;
       }
    
       public JMenuBar methodThatReturnsJMenuBar() {
          JMenu menu = new JMenu("Menu");
          JMenuBar menuBar = new JMenuBar();
          menuBar.add(menu);
          return menuBar;
       }
    }
    

    Then to use in an applet:

    import javax.swing.JApplet;
    
    public class MyApplet extends JApplet {
       public void init() {
          try {
             javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                   createGUI();
                }
             });
          } catch (Exception e) {
             System.err.println("createGUI didn't successfully complete");
          }
       }
    
       private void createGUI() {
          getContentPane().add(new MyPanel());
       }
    }
    

    Or in a JFrame:

    import javax.swing.JFrame;
    
    public class MyStandAlone {
       private static void createAndShowUI() {
          MyPanel myPanel = new MyPanel();
          JFrame frame = new JFrame("MyPanel");
          frame.getContentPane().add(myPanel);
          frame.setJMenuBar(myPanel.methodThatReturnsJMenuBar());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not that I'm trying to prevent 'View Source' or anything silly like that, but
is there any way to send whats in a text view (im trying to
Trying to create a list to return some JSON data to a view. Following
In a view I'm trying to create a new user and then log them
I am trying to access a view inside a splitter from my mainframe. At
I'm trying to create a master detail view of a linq to sql relationship
I am trying to make a search view in Django. It is a search
I'm trying to add a strongly-typed view to the sample app that's created when
I am trying to create a view for a UNION of 2 select statements
I am trying to write a view that will generate a report which displays

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.