 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
A.Tamboer Guest
|
Posted: Thu Feb 24, 2005 10:32 am Post subject: Netbeans |
|
|
I learn myself to understand Java and make as exercise in Netbeans 4.0 a
popup program. A start with Frame and add the popupMenu with items. With the
MousePressed I call "poupMenu.show(this, x,y)" and hope to see the popup
menu. But that doesn't happen. The frame window is on the screen but when I
press the mouse I see the next note;
"Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException:
parent is null". It looks like if "this" can not be found.
Thanks for help.
Arie Tamboer
|
|
| Back to top |
|
 |
proGex Guest
|
Posted: Thu Feb 24, 2005 4:09 pm Post subject: Re: Netbeans |
|
|
would be helpful if you post your code so others can help see where is
wrong
|
|
| Back to top |
|
 |
A.Tamboer Guest
|
Posted: Fri Mar 04, 2005 1:15 pm Post subject: Re: Netbeans |
|
|
The complete code is;
/*
* PopFrame.java
*
public class PopFrame extends java.awt.Frame {
public PopFrame() {
initComponents();
setSize(300,200);
}
private void initComponents() {
popupMenu1 = new java.awt.PopupMenu();
menuBar1 = new java.awt.MenuBar();
menu1 = new java.awt.Menu();
popupMenu1.setLabel("PopupMenu");
setLayout(new java.awt.GridLayout(2, 2));
addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
formMousePressed(evt);
}
});
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
menu1.setLabel("Menu");
menuBar1.add(menu1);
setMenuBar(menuBar1);
pack();
}
private void formMousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if(evt.getModifiers()!=0){
popupMenu1.show(this, evt.getX(), evt.getY());
}
}
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PopFrame().setVisible(true);
}
});
}
private java.awt.Menu menu1;
private java.awt.MenuBar menuBar1;
private java.awt.PopupMenu popupMenu1;
}
"proGex" <edwin.wee (AT) accenture (DOT) com> schreef in bericht
news:1109261354.418465.129400 (AT) f14g2000cwb (DOT) googlegroups.com...
| Quote: | would be helpful if you post your code so others can help see where is
wrong
|
|
|
| Back to top |
|
 |
Bjorn Abelli Guest
|
Posted: Fri Mar 04, 2005 2:44 pm Post subject: Re: Netbeans |
|
|
"A.Tamboer" wrote ...
| Quote: | I learn myself to understand Java and make as exercise in Netbeans 4.0 a
popup program. A start with Frame and add the popupMenu with items. With
the MousePressed I call "poupMenu.show(this, x,y)" and hope to see the
popup menu. But that doesn't happen. The frame window is on the screen but
when I press the mouse I see the next note;
"Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException:
parent is null". It looks like if "this" can not be found.
|
It's not always that the Component provided in "popupMenu1.show" is the
parent.
It can also be another item within the parent, but the latter isn't set in
your case.
To set the parent, you have to add the PopupMenu to the Frame. Put this
somewhere in your code:
this.add(popupMenu1);
http://java.sun.com/j2se/1.3/docs/guide/awt/designspec/popupmenu.html
Note.
This behaviour is different in the corresponding Swing-component JPopupMenu,
which works without that "adding".
http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup
// Bjorn A
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|