JMenuItem ActionEvent Dinamically - Problems

Hi, friends
I am trying to use a JMenu and a JMenuItem wich are dinamicaly
constructed getting data using a Oracle's Database Table.
They are working fine, but I can't figured out how can I add
ActionEvent dinamicaly. The piece of my code is down here:
JMenuBar menuOpcao = new JMenuBar;
JMenu menu[] = new JMenu[5];
JMenuItem submenu[] = new JMenuItem[20];
for (x=0;x<menu.lenght;x++)
menu[x] = new JMenu();
menu[x].setLabel(" menu " + x); //menu 1, menu 2...
for (y=0;y<submenu.lenght;y++)
submenu[y] = new JMenuItem();
submenu[y].setLabel(" submenu " + y); // submenu 1...
submenu[y].addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e){
System.out.println(e);}
menu[x].add(submenu[y];
menuOpcao.add(menu[x]);
My problem: the ActionEvent is not working, because I need know
wich Item I am clicking, so I can execute a query in a Database.
Any Ideas?
Thank you.
null

You don't use MouseListeners. You use ActionListeners.
Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]How to Use Menus for working examples.

Similar Messages

  • JMenuItem and MouseListener Problems

    I add the MouseListener to the JMenu, the event works.
    but when I add the MouseListener to the JMenuItem, it didn't work?
    why?
    the following is my code:                         jMenuItemRelogin = new JMenuItem();
                             jMenuLogin.add(jMenuItemRelogin);
                             jMenuItemRelogin.setText("Relogin");
                             jMenuItemRelogin.addMouseListener(new MouseAdapter(){
                                  public void mouseClicked(MouseEvent evt){
                                       reloginMouseClicked(evt);
                             });

    You don't use MouseListeners. You use ActionListeners.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]How to Use Menus for working examples.

  • JFileChooser problem - it will not display

    I have read the tutorial on JFileChoosers and understand the basics, however, my application will simply not display a File Chooser. I select the menu option "open file" and the command prompt window just spews out dozens of garbage. The code is below if there are any FileChooser "Pros" out there. The FileChooser is selected for loading in the actioPerformed method. Thanks for any assistance.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.*;
    public class DissertationInterface extends JFrame implements ActionListener
         private JPanel onePanel, twoPanel, bottomPanel;
           private JButton quit,search;
           private JMenuBar TheMenu;
           private JMenu menu1, submenu;
         private JMenuItem menuItem1;
         private JFileChooser fc;          //FILE CHOOSER
           private BorderLayout layout;
           //Canvas that images should be drew on
           //drawTheImages Dti;
           //Instances of other classes
         //DatabaseComms2 db2 = new DatabaseComms2();
         //Configuration cF = new Configuration();
           public DissertationInterface()
                setTitle("Find My Pics - University Application") ;
                layout = new BorderLayout();          
                Container container = getContentPane();
                container.setLayout(layout);
                //Dti = new drawTheImages();
              //container.add(Dti);
                quit = new JButton("Quit");
                search = new JButton("Search");
                TheMenu = new JMenuBar();
                setJMenuBar(TheMenu);
                //FILE CHOOSER
                JFileChooser fc = new JFileChooser();     
                fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                //First menu option = "File";
                menu1 = new JMenu("File");
              TheMenu.add(menu1);
                //Add an option to the Menu Item
                menuItem1 = new JMenuItem("OPEN FILE",KeyEvent.VK_T);
            menuItem1.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_1, ActionEvent.ALT_MASK));
              menu1.add(menuItem1);
              menuItem1.addActionListener(this);          //action listener for Open file option
                //CREATE 3 PANELS
                onePanel = new JPanel();
                onePanel.setBackground(Color.blue);
                onePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 200, 400)) ;
                twoPanel = new JPanel();
                twoPanel.setBackground(Color.red);
                twoPanel.setLayout(new GridLayout(5,2,5,5));
                bottomPanel = new JPanel();
                bottomPanel.setBackground(Color.yellow);
                bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
              //ADD COMPONENTS TO THE PANELS
                //Add the menu bar and it's items to twoPanel
              twoPanel.add(TheMenu, BorderLayout.NORTH);
              twoPanel.setAlignmentY(LEFT_ALIGNMENT);
                bottomPanel.add(quit);
                quit.addActionListener(this);          //action listener for button
                bottomPanel.add(search);
                search.addActionListener(this);          //action listener for button
                //ADD PANELS TO THE WINDOWS
                container.add(onePanel, BorderLayout.CENTER);
                container.add(twoPanel,BorderLayout.NORTH);            
                container.add(bottomPanel, BorderLayout.SOUTH);
                //setSize(350,350);
                setVisible(true);
              }//END OF CONSTRUCTOR
            public void leaveWindow()
                 this.dispose() ;
            public static void main(String args[])
            DissertationInterface DI = new DissertationInterface();
            DI.setVisible(true);
            //Display the window.
            DI.setSize(450, 260);
            DI.setVisible(true);
            DI.pack();
         }//End of main method
         protected void processWindowEvent(WindowEvent e)
                super.processWindowEvent(e);
                if(e.getID()== WindowEvent.WINDOW_CLOSING)
                      System.exit(0);
              }//End of processWindowEvent
    //method to resolve button clicks etc
    public void actionPerformed(ActionEvent e)
              //PROBLEM IS HERE !!!!!!! - why won't the file dialogue box open
              if(e.getActionCommand().equals("OPEN"))
                   int returnVal = fc.showOpenDialog(DissertationInterface.this);
                 else if(e.getActionCommand().equals("Quit"))
                      //closeDialog();
                      System.out.println("User interface exited");
                      System.exit(1);
                      leaveWindow();
              else if(e.getActionCommand().equals("Search"))
                      //pass params to database                                 
                 }//end of else if
    } //end of method ActionPerformed
    }//End of class DissertationInterface

    I have done as stated, code compiles/executes but when I select the open file option on my GUI, the command prompt window freezes and no dialogue box is displayed!!!!

  • Add Listener to Unknown Number of JMenuItems

    How can I add an ActionListener to each JMenuItem by cycling through an unknown number of menu items?
    I have a program that prompts the user for a database, then creates a JMenu of table names based on whatever database the user selects.
    This means that I don't know the table names or number of tables that will be added to the JMenu.
    I need to add an ActionListener to EACH JMenuItem. The problem is that I am only able to select one table from the menu. Subsequent menu clicks (on different table names) have no affect on the output.
    Here is an excerpt of my code:
    ResultSet rs = md.getTables(null, null, null, types);
    while (rs.next()) {
    tables.add(rs.getString("table_name"));
    for (Iterator i = tables.iterator(); i.hasNext(); )
    String table = (String) i.next();
    JMenuItem mi = new JMenuItem(table);
    j1.add(mi);
    mi.addActionListener(this);
    [END CODE]
    Thanks for any help you can give!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    I got it. It turns out that I WAS setting the listeners correctly. My additonal output was "hidden" in the window. I found it by pure luck when I expanded the window size.
    I added a line to remove all components from the JPanel before adding a new one and this "refresh" worked.
    Thanks fot the help anyway! It is greatly appreciated.

  • How to display for example "Escape T" on the jmenuitem ?

    Hello everybody,
    I want to know if there it's possible to display for example "Escape T" on the JMenuItem.
    The problem is that it's KeyStroke is null (KeyStroke.getKeyStroke("Escape T")==null).
    So I can't use JMenuItem.setAccelerator().
    Any help ?
    ===============
    Thank you.

    Thank you.
    I've found the solution.

  • Can't find MenuAdapter class,please help

    Hello!In the book I'm reading the author said that if i want to disable some menu items i should add a listener to the JMenu that contains the respective JMenuItems.The only problem is that i don't seem to find the class MenuAdapter.I looked over the net and seen that it should be in the package org.eclipse.swt.events.MenuAdapter.I have installed JDK6u14 and in my c:\jdk6u14\src\org i don't have this eclipse folder.What am i missing guys? Thank you

    Alex_Denny wrote:
    Excuse i'm beginner but are you saying that i should use the Eclipse IDE so that i can have that class? (cause i'm using NetBeans).What he's actually saying is: Ask a specific question. It's impossible to answer such a vague, contextless question. We don't even know what you're trying to do, and I suspect that org.eclipse.swt.* has nothing to do with it, and that your guess that it might has just muddied the water.
    So... What are you trying to do... give us everything you know... and then ask a specific question.
    An SSCCE might be a good place to start.
    Cheers. Keith.

  • Private inner classes

    I'm trying to complete a "turn the lightbulb on and off" program, but when I try to draw circle2 in the
    ButtonListener class I get an error message cannot find symbol. This is in reference to the Graphics
    variable "page" created in the paintComponent method below. Shouldn't the inner class, private or
    public inherit all data variables including objects from the parent class, in this case, the Bulb class? The code is below.
    By the way, this IS NOT a school assignment so any help would be appreciated. I'm just trying to learn
    this language.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Bulb extends JPanel
         private JButton push;
         private Circle circle, circle2;
         private final int DIAMETER = 100;
         private final int X = 10;
         private final int Y = 10;
         public Bulb()
              circle = new Circle(DIAMETER, Color.white, X,Y);
              circle2 = new Circle(DIAMETER, Color.yellow, X, Y); // to separate class
              push = new JButton("Turn on the Bulb");
              push.addActionListener(new ButtonListener());
              add(push);
              setPreferredSize(new Dimension(500, 500));
              setBackground(Color.black);
         public void paintComponent(Graphics page)
              super.paintComponent(page);
              circle.draw(page);
    private class ButtonListener implements ActionListener
              public void actionPerformed(ActionEvent event) //PROBLEM AREA. I GET ERROR MESSAGE STATING
    // "CANNOT FIND SYMBOL" IN REFERENCE TO VARIABLE "PAGE."
    // I THOUGHT THE INNER CLASS INHERITS ALL DATA FROM
    // PARENT CLASS SUCH AS "PAGE."
                   circle2.draw(page);
    }

    There are fields, which are associated with either a class or an object (and thus live in the heap in an object on the heap), and there are local variables, which are associated with methods and threads (i.e., a method invoked within a thread, and which thus live on the stack).
    They're not the same thing.
    You can't use a local variable in your paintComponent method in a different method.
    Anyway you're designing your class wrong. Think model-view-controller. You have the model: a bunch of state and possibly behavior that represents the thing being seen, modified, and displayed. You have the view, which is how you see the model. And you have the controller, which modifies the model.
    Your event handlers are part of the controller. They should change the model.
    Your paintComponent method is part of the view.
    So the event handlers should change some data, e.g., add a note that a circle should be displayed.
    Then your paintComponent method should look at the data and act accordingly -- e.g., see that there's a circle to be displayed, and display it.

  • JMenu doesn't dissapear when menu is losing focus

    Hello everyone!
    I have a JMenu with several JMenuItems. The problem is that the JMenu doesn't dissapear when the menu is losing it's focus, for example when I click somewhere in the application window. I use the Windows look and feel for my application.
    Any ideas ? Thanks.

    Add some try/catch block. My guess is that you bump in some NullPointerException.

  • Additional Keyboard on serial port

    Can I extend the KeyEvent class to handle more than those 114 keys?
    I have an additional keyboard hooked up to the serial port.
    I generate special custom KeyEvents with special KeyCodes after receiving certain bytews from the com port. I create new KeyStrokes using this KeyCode to be able to address this KeyStroke in a JMenuItem.
    The problem is, that the standard KeyEvent spits out: "Unknown KeyCode:..." if I want to set the according KeyStroke as accelerator for a JMenuItem. This seems to stem from the method:
    public static String getKeyText(int keyCode)
    in the standard KeyEvent thatonly gets the text for KeyCodes between a lower and upper limit and my KeyCodes exceed this limit of course, since there is no space left.
    Regards
    Joerg Hoebelmann

    And how about changing your scenario a little bit?
    Since you have a special program to catch signals on COM port, you can enhance it with a logic to run the appropriate action from the menu directly.
    If you want to stick to your solution you can try to take a look on the KeyEvent.java (source of KeyEvent.class) - maybe there's a possibility to break the limitation of 114 keys (but personally, I think it will not be possible)

  • Problem with PremiereProCS5 and AfterEffectsCS5 Dinamic Link!

    Problem with PremiereProCS5 and AfterEffectsCS5 Dinamic Link!
    I installed PremiereProCS4, and after, "Adobe Master Collection Suite CS5" in Italian Language, with PremiereProCS5 and AfterEffectsCS5 on OS Windows7x64Bit.
    I made a first composition with AfterEffects, from PremierePro by choosing "Adobe Dinamic Link">"Replace with AE Composition".
    After that, I made another second version of the same project, directly with AfterEffects.
    I want replace this AE version with existing version, in PremierePro.
    Thus, I selected "Adobe Dinamic Link">"Import AE Composition".
    1) But, the problem is that the new, fresh AE composition is not found!
    The Dinamic Link, in PremierePro, doesn't refresh the window where it is located the new AE Composition called "n°2" made last with AE, (not with DynamicLink)!
    There are available 3 files, that I made, but all the files display only the old composition called "n°1", made with DynamicLink, and with "Replace with AE Composition" command!
    The composition made with AE directly, is not displayed!
    Why?
    In fact, I tried to right click the clip, in PremiereProCS5 timeline, choosed "Replace with Clip">"From Folder" and selected the last imported AE composition: the composition is allways the OLD file made with DynamicLink, not the file made directly with AE!
    Why?
    Help!
    Horsepower0171.

    "...or if you must use multiple projects, start each one from scratch instead of duplicating and renaming..."
    Yes!
    I made from scratch these new projects with AECS5, called:
         "Montaggio_02_CS5_04_Franzi_AECS5 - Composizione collegata 02.avi" and
         "Montaggio_02_CS5_04_Franzi_AECS5 - Composizione collegata 03.avi",
    not renamed, nor duplicated.
    -But PremierePro and DynamicLink doesn't display those in the window!

  • Creation  of components in dinamic way. Problem with threads....?

    hi,
    I am trying to add components (JTextFields) to a JPanel in dynamic way.
    I would like that the user decides the number of the components, to
    be created, for executing a function by clicking a button.
    But clicking on the button, the elaboration doesn't produce the creation
    of the JTextFields.
    Debugging the code I saw that the same function works well
    when it is called from the normal data flow of the elaboration
    instead that it is called from inside a listener.
    It is hard for me to understand the reason why this
    happens, as well I could think that this problem could happen
    because the execution of different threads.
    But I am not able to manage those kind of situations....
    I would like to have a little help
    thank you
    regards
    tonyMrsangelo.
    To reproduce the problem I post some code where the function (setComponentInThePanel())
    is called from the constructor of the class and from the listener of a JButton.
    package labels;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.JTextField;
    import javax.swing.SpinnerNumberModel;
    public class LabelsDialogMain extends JFrame {
        PanelCanvas jPanCanvas = new PanelCanvas();
        PanelDesign jPanDesign = new PanelDesign();
        PanelCommands jPanCommands = new PanelCommands(jPanDesign);
        /** Creates new form MainLabelsDialog */
        public LabelsDialogMain() {
            java.awt.GridBagConstraints gridBagConstraints;
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(new java.awt.GridBagLayout());
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.gridheight = 2;
            getContentPane().add(jPanCanvas, gridBagConstraints);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 3;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.gridheight = 2;
            getContentPane().add(jPanDesign, gridBagConstraints);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.gridwidth = 4;
            gridBagConstraints.gridheight = 2;
            getContentPane().add(jPanCommands, gridBagConstraints);
            pack();
         * @param args the command line arguments
        public static void main(String args[]) {
             LabelsDialogMain mld = new LabelsDialogMain();
             mld.setVisible(true);
    class PanelCanvas extends JPanel {
        public PanelCanvas() {
            Dimension d = new Dimension(400,200);
            setPreferredSize(d);
            setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Panel Canvas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 11), new java.awt.Color(0, 255, 255))); // NOI18N
    } // class PanelCanvas
    class PanelDesign extends JPanel {
        JTextField textField [];
        public PanelDesign() {
            Dimension d = new Dimension(400,200);
            setPreferredSize(d);
            setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Panel Design", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 11), new java.awt.Color(0, 255, 255))); // NOI18N
        void setComponentInThePanel(int dim ){
             textField = new  JTextField[dim];
             for (int i = 0; i < dim; i++){
                 textField[i] = new  JTextField("----- " + i);
                 add(textField);
    System.out.println("executed the nmbr: " + i);
    repaint();
    } // setComponentInThePanel()
    } // class PanelDesign
    class PanelCommands extends JPanel {
    PanelDesign panelDesign;
    private javax.swing.JLabel jLblRowNmbr;
    private javax.swing.JSpinner jSpinner;
    JButton dummyButton = new JButton("button");
    public PanelCommands(PanelDesign pnlDesign) {
    panelDesign = pnlDesign;
    Dimension d = new Dimension(800,200);
    setPreferredSize(d);
    setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Panel Cmmands", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 11), new java.awt.Color(0, 255, 255))); // NOI18N
    jLblRowNmbr = new javax.swing.JLabel();
    jSpinner = new JSpinner();
    jLblRowNmbr = new JLabel();
    add(jLblRowNmbr);
    add(jSpinner);
    add(dummyButton);
    jSpinner.setModel(new javax.swing.SpinnerNumberModel(Short.valueOf((short)1), Short.valueOf((short)1), null, Short.valueOf((short)1)));
    final SpinnerNumberModel sm = (SpinnerNumberModel) this.jSpinner.getModel();
    jLblRowNmbr.setText("N. of the rows");
    // panelDesign.setComponentInThePanel(4); "take out the comment of this row to get the creation of JTextFields"
    dummyButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Number amp = sm.getNumber();
    int ampInt = amp.intValue();
    panelDesign.setComponentInThePanel(ampInt);
    // panelDesign.setComponentInThePanel(4);
    JOptionPane.showMessageDialog(jSpinner, "spinner = " + ampInt);
    } // class PanelCommands

    When you add/remove components to a panel when the GUI has already been created then you need to use:
    panel.revalidate();
    panel.repaint();

  • Problems with Dinamic Link between Premiere pro CC and After Effects CC

    I'm having serious problems with dinamic link between premiere pro and after effects, really serious problems that have 2 big projects in trouble (a documentary and a video clip) and I had to redo all the work pipeline to the consumer.
    The documentary for a spanish TV was made on CC 2014 and a video clip was made on CC. Both of them with a lot of after effects composition in the premiere pro timeline. Render freeze, a lot of playback issues, and many more problems... Until I decided to remove these links between premiere and after effects and render out all the after effects compositions one by one and insert as clips in premiere pro. 1 week working away with back and fourth.
    I've got a huge workstation:
    i7 4990
    32Gb ram
    GTX780 3gb
    256 gb system ssd
    2 Tb project storage
    *All my hardware and software are update.
    I know that a lot of folks are on the same huge problem and I want to ask everyone:
    How do you save this?
    What is your pipeline?
    Are there any solution?
    Best practice to use dinamic link in a huge project?
    Thanks,
    Ruben Gimenez.
    R&D iceblink.es
    www.rambot.es

    Thank You, Jim -
    Unfortunately that specifically did not work.
    Based on another comment sent to me, here is what did.
    In PProCC
    File > Adobe Dynamic Link > New After Effects Composition
    In AECC
    From that composition created from PPro, I imported the project (aep) initially created in AECC from another team member. Saved the file.
    Back in PProCC
    File > Adobe Dynamic Link > Import After Effects Composition
    Magic.

  • Problem with charset  ISO-8859 with dinamic action

    Hello
    I migrated my application that was Apex 3.2, and now Apex is 4.2.3, but a have a problem when I'm use Dynamic Action with ISO-8859.
    When I used a filter "ação" in dinamic action filter mounted by the apex presents 'aà § à £ o.'
    If I force use of PlsqlNLSLanguage = BRAZILIAN PORTUGUESE_BRAZIL.UTF8 in Dads, works correct.
    Please, Help me! I need to keep ISO-8859!
    Thanks

    Using another example to illustrate the problem… I
    found an apparent solution using "encodeURI".
    It sees:
    quote:
    BEFORE:
    function SaveMsg()
    if (document.sender.message == "" )
    return false;
    var mensagem=document.sender.message.value;
    ds2.setURL('responsexml.asp?action=add'&msg='+mensagem);
    ds2.loadData();
    document.sender.message.value="";
    document.sender.message.focus();
    When the entrance of the changeable "mensagem" was
    “João” was recorded in archive XML as
    “Joo” ...
    input: "João"
    output: "Joo"
    quote:
    AFTER:
    function SaveMsg()
    if (document.sender.message == "" )
    return false;
    var mensagem=encodeURI(document.sender.message.value);
    ds2.setURL('responsexml.asp?action=add'&msg='+mensagem);
    ds2.loadData();
    document.sender.message.value="";
    document.sender.message.focus();
    Now ...
    input: "João"
    output: "João"
    This would be a good solution? I will not have problems,
    right? Some opinion/suggestion on this solution?

  • JMenuItem Problems ?

    hi,i got problems,i cannot view the JMenuItem ?what's wrong ?
    satu.java
    import java.awt.BorderLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    public class satu {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              JFrame.setDefaultLookAndFeelDecorated(true);
              final JFrame appp = new JFrame("TEST ");
              appp.setSize(150,180);
              appp.setUndecorated(true);
              appp.setResizable(false);
              testmenu m = new testmenu();
              appp.setJMenuBar(m.createbar());
              appp.setContentPane(m.createContentPane());
              m.start();
              appp.setSize(540,430);
              //dua m = new dua(appp);
            //m.init();
              //TestHeaderRenderer m = new TestHeaderRenderer();
              appp.add(m,BorderLayout.CENTER);   
             appp.setVisible(true);
             //appp.setLocationRelativeTo(null);
              appp.addWindowListener(new WindowAdapter() {
                           public void windowClosing(WindowEvent evt) {
                          appp.setVisible(false);
                          appp.dispose();
    }testmenu.java
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.Panel;
    import java.awt.event.KeyEvent;
    import java.applet.*;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class testmenu extends Applet {
         String sessionid,usersession;
         JMenuItem menuout;
        Panel contentPane;
        public JMenuBar createbar(){
              JMenuBar menu1 = new JMenuBar();
              JMenu menustart = new JMenu("File");
              menustart.setMnemonic(KeyEvent.VK_F);
            JMenu menutool = new JMenu("Tools");
            menutool.setMnemonic(KeyEvent.VK_T);
              menuout = new JMenuItem("New");
              menustart.add(menuout);
              menu1.add(menustart);
              menu1.add(menutool);
              return menu1;
         public Container createContentPane() {
              contentPane = new Panel();
              contentPane.setBackground(Color.BLACK);
            gbrutama x = new gbrutama();
            contentPane.add(x);
            return contentPane;
    class gbrutama extends Applet{
       public gbrutama() {
       public void paintComponent(Graphics g){
        g.drawLine(0,0,200,200);
    }when i click on menu "File",why i cannot view "New" JMenuItem ?Please someone help me,please...
    thanks.

    for your old code it worked :Check it
    import java.awt.BorderLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.Panel;
    import java.awt.event.KeyEvent;
    import java.applet.*;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class satu {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              JFrame.setDefaultLookAndFeelDecorated(true);
              final JFrame appp = new JFrame("TEST ");
              appp.setSize(150,180);
              appp.setUndecorated(true);
              appp.setResizable(false);
              testmenu m = new testmenu();
              appp.setJMenuBar(m.createbar());
              appp.setContentPane(m.createContentPane());
              m.start();
              appp.setSize(540,430);
              //dua m = new dua(appp);
            //m.init();
              //TestHeaderRenderer m = new TestHeaderRenderer();
              appp.add(m,BorderLayout.CENTER);
             appp.setVisible(true);
             //appp.setLocationRelativeTo(null);
              appp.addWindowListener(new WindowAdapter() {
                           public void windowClosing(WindowEvent evt) {
                          appp.setVisible(false);
                          appp.dispose();
    //testmenu.java
    class testmenu extends Applet {
         String sessionid,usersession;
         JMenuItem menuout;
        javax.swing.JPanel contentPane;
        public JMenuBar createbar(){
              JMenuBar menu1 = new JMenuBar();
              JMenu menustart = new JMenu("File");
              menustart.setMnemonic(KeyEvent.VK_F);
            JMenu menutool = new JMenu("Tools");
            menutool.setMnemonic(KeyEvent.VK_T);
              menuout = new JMenuItem("New");
              menustart.add(menuout);
              menu1.add(menustart);
              menu1.add(menutool);
              return menu1;
         public Container createContentPane() {
              contentPane = new javax.swing.JPanel();
              contentPane.setOpaque(true);
              contentPane.setBackground(Color.BLACK);
            gbrutama x = new gbrutama();
            contentPane.add(x);
            return contentPane;
    class gbrutama extends Applet{
       public gbrutama() {
       public void paintComponent(Graphics g){
        g.drawLine(0,0,200,200);
    }wait let me see your new modified code...

  • JMenuItem.setIcon problem

    When I create a JMenuItem and add an icon, the menu item text is greyed out (it's not disabled). When I remove the setIcon, the text appears normally. This is L&F independent.
    I've tried various things to force the foreground color to black, but nothing works.
    I'm using JRE 1.4.2_04.
    Any suggestions?
    Thanks
    Ross

    Now that I think about it, I remember that there are quite a few problems with setting button background colors due to conflicts with Windows desktop styles and the native button code. I assume that's involved here since JMenuItems are buttons.
    However, in this particular case, I'm not trying to set any colors, just setting an icon. Why wouldn't that work?

Maybe you are looking for

  • When I try to open a PSD file, Photoshop opens the new file dialog box instead

    This does not happen with all files, but I have a few that have become corrupted it seems. I have previously opened, edited and saved these files without any difficulty, but now they will not open. This is what Photoshop shows when I try to open the

  • M-Audio Box and Mic

    is there any way to talk on ichat using a microphone and m-audiobox? thanks

  • Need solution for the query

    hi All, I have 3 tables 1)PREVILEGES (groupname, previleges(values y or n only)) 2)GROUPS (groupid, groupname) 3) USERS (uname, groupname). Here each user belongs to one group, each user hav a default previlege means example if user is consutant then

  • Can Logic 8 pro be re-installed?

    I plan on getting a new mac, and want to reset my mac to factory settings to i can sell it on. Can i install my Logic 8 pro onto the new system with all the discs etc I already have, or is the serial code now not valid? Thanks

  • I cannot open itunes in recovery mode

    i need to restore my iphone because it has been disabled for i have forgotten the passcode. it says connect to iTunes so i connect to iTunes, but while on recovery mode i cannot open iTunes it hanged. please i badly need your help..