# Javax swing JFrame in the main processing PApplet

**URL:** https://discourse.processing.org/t/javax-swing-jframe-in-the-main-processing-papplet/16122
**Category:** Coding Questions
**Created:** [December 4, 2019, 7:02pm UTC](https://discourse.processing.org/t/javax-swing-jframe-in-the-main-processing-papplet/16122 "2019-12-04T19:02:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![GeorgeJava](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/georgejava/32/7646_2.png) [@GeorgeJava](https://discourse.processing.org/u/GeorgeJava)
#### Post date: [December 4, 2019, 7:02pm UTC](https://discourse.processing.org/t/javax-swing-jframe-in-the-main-processing-papplet/16122/1 "2019-12-04T19:02:38Z")

</div>

Hello i search somewhere the example of the menu in the main processing sketch, but when i want to add something more, like buttons, labels etc. it cant render or display it… how to make it working ?

```auto
Menu_bar mp;
void setup() {
  size(1600, 900);
  surface.setResizable(true);
  buildMenuBar();
}

void draw() {
  ellipse(mouseX, mouseY, 30, 30);
}

void buildMenuBar() {
  mp = new Menu_bar(this, "Media");
}

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JButton;
import javax.swing.JToggleButton;
import java.awt.Color;
import javax.swing.JTabbedPane;

public class Menu_bar extends JFrame implements ActionListener {
  JFrame frame;
  JMenuItem new_file;

  JPanel panel;

  public Menu_bar(PApplet app, String name) {
    frame = (JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas)app.getSurface().getNative()).getFrame();

    frame.setTitle(name);

    panel = new JPanel(); 
    panel.setOpaque(false);

    // ADDING PANEL WITH BUTTON

    JButton exit = new JButton("Exit");
    exit.setBounds(300, 300, 300, 300);  
    exit.addActionListener(this);
    panel.add(exit);

    // Creates a menubar for a JFrame
    JMenuBar menu_bar = new JMenuBar();
    // Add the menubar to the frame
    frame.setJMenuBar(menu_bar);
    // Define and add two drop down menu to the menubar
    JMenu import_menu = new JMenu("import");
    JMenu text_menu = new JMenu("text");
    JMenu shape_menu = new JMenu("shape");
    JMenu image_menu = new JMenu("image");
    JMenu video_menu = new JMenu("video");

    JMenu submenu = new JMenu("Submenu");

    JMenuItem test = new JMenuItem("Testando");

    menu_bar.add(import_menu);
    menu_bar.add(text_menu);
    menu_bar.add(shape_menu);
    menu_bar.add(image_menu);
    menu_bar.add(video_menu);

    test.addActionListener(this);
    submenu.add(test);

    import_menu.add(submenu);

    // Create and add simple menu item to one of the drop down menu
    new_file = new JMenuItem("Import file");
    JMenuItem new_folder = new JMenuItem("Import folder");
    JMenuItem action_exit = new JMenuItem("Exit");

    new_file.addActionListener(this);
    new_folder.addActionListener(this);
    action_exit.addActionListener(this);

    import_menu.add(new_file);
    import_menu.add(new_folder);

    import_menu.addSeparator();

    import_menu.add(action_exit);
    frame.setVisible(true);
  }

  public void actionPerformed(ActionEvent e) { 
    String str = e.getActionCommand(); 

    Object source = e.getSource();
    if (source == new_file) {
      println("Selected new file");
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![GeorgeJava](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/georgejava/32/7646_2.png) [@GeorgeJava](https://discourse.processing.org/u/GeorgeJava)
#### Post date: [December 4, 2019, 8:04pm UTC](https://discourse.processing.org/t/javax-swing-jframe-in-the-main-processing-papplet/16122/2 "2019-12-04T20:04:20Z")

</div>

It is easy, just set Content Pane, DONE ! thanks 😛  
Only add line somewhere under adding panel…

`frame.setContentPane(panel);`

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [October 21, 2022, 12:56am UTC](https://discourse.processing.org/t/javax-swing-jframe-in-the-main-processing-papplet/16122/3 "2022-10-21T00:56:04Z")

</div>

@GeorgeJava

Can you share the source code you have solved?  
I am also studying JFrame.

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [October 21, 2022, 1:45am UTC](https://discourse.processing.org/t/javax-swing-jframe-in-the-main-processing-papplet/16122/4 "2022-10-21T01:45:30Z")

</div>

Have you seen this recent post to Gallery: [https://discourse.processing.org/t/swing-components-in-default-processingwindow/35483](https://discourse.processing.org/t/swing-components-in-default-processingwindow/35483)
