I try to add a menu bar on the top of my desktop, i’m close but I fail :slight_smile
Obviously I don’t want open a new frame, but I cannot figure the way to do that.
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;
public class Menu_bar extends JFrame {
String name;
int width;
int height;
public Menu_bar(String name, int width, int height) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
this.name = name;
this.width = width;
this.height = height;
setTitle(name);
setSize(this.width,this.height);
// Creates a menubar for a JFrame
JMenuBar menu_bar = new JMenuBar();
// Add the menubar to the 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");
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);
// Create and add simple menu item to one of the drop down menu
JMenuItem new_file = new JMenuItem("Import file");
JMenuItem new_folder = new JMenuItem("Import folder");
JMenuItem action_exit = new JMenuItem("Exit");
import_menu.add(new_file);
import_menu.add(new_folder);
import_menu.addSeparator();
import_menu.add(action_exit);
// Add a listener to the New menu item. actionPerformed() method will
// invoked, if user triggred this menu item
new_file.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("You have clicked on the new action");
}
});
}
public void exec() {
Menu_bar me = new Menu_bar(this.name, this.width, this.height);
me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
me.setVisible(true);
}
}
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;
public class Menu_bar {
JFrame frame;
public Menu_bar(PApplet app, String name, int width, int height) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
frame = (JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas)app.getSurface().getNative()).getFrame();
frame.setTitle(name);
// 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");
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);
// Create and add simple menu item to one of the drop down menu
JMenuItem new_file = new JMenuItem("Import file");
JMenuItem new_folder = new JMenuItem("Import folder");
JMenuItem action_exit = new JMenuItem("Exit");
import_menu.add(new_file);
import_menu.add(new_folder);
import_menu.addSeparator();
import_menu.add(action_exit);
// Add a listener to the New menu item. actionPerformed() method will
// invoked, if user triggred this menu item
new_file.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("You have clicked on the new action");
}
}
);
frame.setVisible(true);
}
Thx @quark that’s great because in my case I don’t need P2D or P3D but if I need one day to do that with an OPENGLrendering is not possible if I understand well ?
JFrame and JMenubar are part of the Java Swing frame work and is incompatible with OpenGL and GLWindow, so it won’t be possible to do it this way. As GoToLoop pointed out you would need to find the OpenGL equivalent of menubars, but as far as I know there isn’t one.
There is an alternative to using P2D and P3D, and that is to use JAVA2D for the main sketch and then use OpenGL off-screen buffers for drawing which are then copied to the main sketch display in the draw() method. G4P uses this in its latest version for the GView control.
Now the problem very very important is catching the information and I don’t any possibility to do that.
How catch something in this part to use in other place of my code. I try to pass argument, but the arg need to be static
And I don’t find on the internet a method to catch something the JMenuItem like boolean statement .
I figure the probleme is around this part:
public void actionPerformed(ActionEvent arg0) {
println("happen when is clicked");
}
Finally i need to make a bridge from P3D / P2D to JFrame but you example is very hard to understand… after I catch that : com.jogamp.newt.opengl.GLWindow glw = (com.jogamp.newt.opengl.GLWindow)app.getSurface().getNative();what the next step ?
On that CanvasResizeWatcher.java, the only thing it uses getNative() for, regardless of the renderer, is to add & remove listeners to the sketch’s canvas.