We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › maybe more a java question
Page Index Toggle Pages: 1
maybe more a java question (Read 1149 times)
maybe more a java question
May 18th, 2009, 3:17am
 
I used Processing for my Bachelor thesis and now i work with it again in the same way.
There i don't use it as Applet but add it to a JFrame. It actual works ok if you get it into it, but the bad problem is that the Applet draws itself all over everthing that is in the Frame to(Menus, InternalFrames)
I wrote the simplest program that shows the Problem.

Code:


import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import processing.core.PApplet;

public class InternPFrame extends JFrame {

public InternPFrame() {
this.setSize(400, 400);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
// this needs to be because of the size
this.setVisible(true);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
setVisible(false);
int width = this.getLayeredPane().getWidth();
int height = this.getLayeredPane().getHeight();
//
getContentPane().add(new PA(width, height));
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Test");
JMenuItem menuItem = new JMenuItem("Anything");
menu.add(menuItem);
menuBar.add(menu);
this.setJMenuBar(menuBar);
this.setVisible(true);
}

class PA extends PApplet {

int w, h;

public PA(int w, int h) {
this.w = h;
this.h = w;
init();
}

public void setup() {
size(w, h);
background(0);
}
}

public static void main(String[] args) {
InternPFrame pf = new InternPFrame();
}
}


There is a menu, you can see it without the
Applet
(if you comment
getContentPane().add(new PA(width, height));
out)
Now its very necessary that i can solve the problem. I thought about setting it into another layer that is under the content, but in real there are more JPanel besides the Applet, so this structure will get lost.
Does anybody know, how to set the Applet so it does paint over everything all. Its also possible to turn its drawing temporary off for this
thanks for help,
ramin
Re: maybe more a java question
Reply #1 - May 18th, 2009, 3:36am
 
I am not specialist of the question but I recall having seen there is a problem of mixing heavyweight components (native, AWT, like Processing's surface) and lightweight ones (drawn in Java, Swing). The AWT ones, being drawn by the system, are always on top.
I think I saw this because the problem is supposed to be resolved in the latest Java (1.6) versions. If you use a Mac, you are out of luck...
Re: maybe more a java question
Reply #2 - May 18th, 2009, 4:18am
 
hi PhiLho, thanks for your answer.
i use windows. but in eclipse the newest java. you mean its because p5 still uses 1.3?
Re: maybe more a java question
Reply #3 - May 18th, 2009, 4:26am
 
No, Processing uses, on Windows, Java 1.6 (AFAIK) or at least 1.5.
1.3 is only the level of syntax...

Maybe there is some voodoo to do to make this overlay thingy to work, I don't know.
Re: maybe more a java question
Reply #4 - May 18th, 2009, 4:28am
 
Short summary found at Canvas rendered over JCombobox menu. There is a link, I will follow it and update here.

OK, Mixing heavy and light components shows that you can set an option to make heavyweight menus, which might work on more versions of Java.
Re: maybe more a java question
Reply #5 - May 18th, 2009, 6:12am
 
thanks, im gonna read the article and see if it can help.
the local shaman is also already preparing the ingredients
Page Index Toggle Pages: 1