how can I create gui pop-ups

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenrocks
    New Member
    • Oct 2008
    • 25

    how can I create gui pop-ups

    can u guys show me an example of how to make gui pop-ups..thx :)
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    See the API specs for JOptionPane and for the JDialog class.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Don't forget the good ol' JPopupMenu!

      kind regards,

      Jos

      Comment

      • kenrocks
        New Member
        • Oct 2008
        • 25

        #4
        well I read the JPopupmenu api can u pls..explain to me what the show method fully does and is it needed to be placed under an addPopupmenulis tener method?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          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,

          Jos

          Comment

          • kenrocks
            New Member
            • Oct 2008
            • 25

            #6
            in the show method "show(Compo nent invoker, int x, int y) "can u please explain to me what the Component invoker is..thx :D

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by kenrocks
              in the show method "show(Compo nent invoker, int x, int y) "can u please explain to me what the Component invoker is..thx :D
              Suppose you click your mouse on a JPanel; this panel has a MouseEventListe ner
              installed, the listener creates a JPopUpMenu and shows it using the coordinates
              of the mouse and the JPanel as the invoking component.

              kind regards,

              Jos

              Comment

              • kenrocks
                New Member
                • Oct 2008
                • 25

                #8
                what if I want to make a pop-up that belong to another class do i still have to use the jpopupmenu class?

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by kenrocks
                  what if I want to make a pop-up that belong to another class do i still have to use the jpopupmenu class?
                  The class you want to popup has to be able to show itself anywhere on the
                  screen (Windows, JDialogs, JOptionPanes etc); but feel free to pop them up.
                  Why do you want to do that?

                  kind regards,

                  Jos

                  Comment

                  • kenrocks
                    New Member
                    • Oct 2008
                    • 25

                    #10
                    Hi Iwasn't that succesful in pulling pop-ups off..mind giving me a sample gui pop-up interface...thx :D

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      What did you try?

                      Comment

                      • kenrocks
                        New Member
                        • Oct 2008
                        • 25

                        #12
                        I 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

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by kenrocks
                          I 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
                          Well, show us the improperly used 'codes' then so we can have an idea what
                          you're up to.

                          kind regards,

                          Jos

                          Comment

                          • kenrocks
                            New Member
                            • Oct 2008
                            • 25

                            #14
                            [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

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              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,

                              Jos

                              Comment

                              Working...