2011-03-15 6 views
0

JComboBoxは、add(PopUpMenu)add(JMenuItem)です。JComboのサブメニュー

私のクラスはJComboBoxを拡張しています。私はJPopUpMenuを作成しますが、JComboBoxをクリックすると表示されません。代わりに何も表示されません。何か案は?

 


    JPopupMenu Pmenu = new JPopupMenu(); 
    JMenu textAndDataMenu = new JMenu("Text and Data"); 

    HashMap textAndData = new HashMap(); 

    public ComboMenu() 
    { 
     super(); 
     setUpTextAndData(); 
     add(Pmenu); //----------this is where I add the menu 

    } 

    public void setUpTextAndData() 
    { 
     textAndData.put("Basic Text Box", TextBox.class); 
     textAndData.put("Clear Text Box", ClearTextBox.class); 
     textAndData.put("Table", Table.class); 
     textAndData.put("Interactive Table", InteractiveTable.class); 
     textAndData.put("Graph", Graph.class); 

     Set textAndDataKeys = textAndData.keySet(); 
     JMenuItem newMenuItem; 
     for(String currKey : textAndDataKeys) 
     { 
      newMenuItem = new JMenuItem(currKey); 
      newMenuItem.addActionListener(this); 
      textAndDataMenu.add(newMenuItem); 
     } 

     Pmenu.add(textAndDataMenu); 
    } 
 

答えて

0

EDIT:ネヴァーマインド...あなたが知っている、私はしばらくの間でこれらをめちゃくちゃしていません。

私はすべてを行う必要があると思う:

Pmenu.setInvoker(this); 

あなたのコンストラクタでそれを追加する前に。

+0

JMenusをPopUpMenuに追加する前にJMenusを追加して、JMenusがサブメニューになるようにしました。私が達成しようとしているのはJComboBoxです.JComboBoxをクリックすると、ネストされたアイテムにアクセスできます。どのようにこれを達成するための任意のアイデア? – user489041

+0

私の編集を見て、私はそれを見て間違った道を下ったと思う。 –

関連する問題