🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
1 messages
1 total messages Started by kc Thu, 15 Apr 2004 16:08
popup combobox
#1040
Author: kc
Date: Thu, 15 Apr 2004 16:08
54 lines
2638 bytes
Hi
I  have a jpopupmenu on the right click of the mouse.
The popupmenu has a number it JMenuItem's.
I would like one to be a JMenu where when the mouse mouse over this menu 
  a combobox pops up. This is similar to a submenu, but instead of the 
submenus being several JMenuItem I want it to be one jcombobox with 
several items in it.

I have tried to play around with BasicComboPopup but it doesn't do what 
I want it to do

Here is the code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.*;
public class ComboBoxPopupMenuDemo extends JPanel
{
   BasicComboPopup myPopup;
   JComboBox petList;
   JPopupMenu menu=new JPopupMenu();
   public ComboBoxPopupMenuDemo()
   {
     super(new BorderLayout());
     String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig", 
"Fish", "Horse", "Cow", "Bee", "Skunk" };
     petList = new JComboBox(petStrings);
       myPopup=new BasicComboPopup(petList);
       final JLabel lab=new JLabel(" ");
       lab.addMouseListener(new MouseAdapter()
       {
         public void mouseClicked(MouseEvent e)
         {
           menu.add(myPopup);
          // menu.add(new JMenuItem("Test"));
           menu.show(lab,e.getX(),e.getY());
         }
       });
       add("Center",lab);
       setPreferredSize(new Dimension(200,100));
     }
     public static void main(String s[])
     {
       JFrame frame = new JFrame("ComboBoxDemo");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setContentPane(new ComboBoxPopupMenuDemo());
       frame.pack();
       frame.setVisible(true);
     }
   }

Any ideas
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads