can u guys show me an example of how to make gui pop-ups..thx :)
how can I create gui pop-ups
Collapse
X
-
The show method simply shows the popup menu somewhere on top of another
JComponent at a certain location (normally the mouse position). You only need
PopupMenuListen ers if something is interested in the state of the popup menu.
It's all in the API documentation.
kind regards,
JosComment
-
Suppose you click your mouse on a JPanel; this panel has a MouseEventListe nerOriginally posted by kenrocksin the show method "show(Compo nent invoker, int x, int y) "can u please explain to me what the Component invoker is..thx :D
installed, the listener creates a JPopUpMenu and shows it using the coordinates
of the mouse and the JPanel as the invoking component.
kind regards,
JosComment
-
The class you want to popup has to be able to show itself anywhere on theOriginally posted by kenrockswhat if I want to make a pop-up that belong to another class do i still have to use the jpopupmenu class?
screen (Windows, JDialogs, JOptionPanes etc); but feel free to pop them up.
Why do you want to do that?
kind regards,
JosComment
-
Well, show us the improperly used 'codes' then so we can have an idea whatOriginally posted by kenrocksI tries the sample that java provided as well as using JDialog and JOptionPane and I just can't mange to pull it off because I can't seem to use the codes properly....... plsss.help
you're up to.
kind regards,
JosComment
-
[CODE=java]import java.awt.*;
import java.awt.event. *;
import javax.swing.*;
import javax.swing.eve nt.*;
public class Pop extends JPanel implements ActionListener {
private JButton jcomp1;
//Up a=new Up();
public Pop() {
//construct components
jcomp1 = new JButton ("Button 1");
//adjust size and set layout
setPreferredSiz e (new Dimension (150, 63));
setLayout (null);
//add components
add (jcomp1);
//set component bounds (only needed by Absolute Positioning)
jcomp1.setBound s (10, 15, 100, 20);
JMenuItem menuItem;
//Create the popup menu.
JPopupMenu popup = new JPopupMenu();
menuItem = new JMenuItem("A popup menu item");
menuItem.addAct ionListener(thi s);
popup.add(menuI tem);
menuItem = new JMenuItem("Anot her popup menu item");
menuItem.addAct ionListener(thi s);
popup.add(menuI tem);
}
public void actionPerformed (ActionEvent e) {
if(e.getSource( )==jcomp1)
{
popup.setVisibl e(true);
}
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
frame.getConten tPane().add (new Pop());
frame.pack();
frame.setVisibl e (true);
}
}
[/CODE]
this is my code when I press the certain button i want a pop-up to show...plsss... help..thx :)Comment
-
1) Your popup variable is a variable local to your constructor so it can't be seen
from your actionPerformed method. Make it a member variable just as your
jcomp1 button.
2) You are adding the action listener to invisible components in the popup menu.
Add the action listener to the button instead.
3) use the 'show' method instead of just the 'setVisible' method.
kind regards,
JosComment
Comment