JComboBox added to JPopupMenu

Hi,
I have the following issue. I am trying to find a way to edit a cell in JTable by making selection from 4 comboboxes. The idea was to show JPopupMenu once the cell editor gains focus, and then allow to make selection from 4 comboboxes shown on the popup. The issue is once I start to edit a combobox, JPopupMenu disappears. Is there a was to show a popup, and still keep another popup showing?
Thanks!!

Hi,
I have the following issue. I am trying to find a way
to edit a cell in JTable by making selection from 4
comboboxes. The idea was to show JPopupMenu once the
cell editor gains focus, and then allow to make
selection from 4 comboboxes shown on the popup. The
issue is once I start to edit a combobox, JPopupMenu
disappears. Is there a was to show a popup, and still
keep another popup showing?
I have the following issue. I am trying to find a way
to edit a cell in JTable by making selection from 4
comboboxes. The idea was to show JPopupMenu once the
cell editor gains focus, and then allow to make
selection from 4 comboboxes shown on the popup. The
issue is once I start to edit a combobox, JPopupMenu
disappears. Is there a was to show a popup, and still
keep another popup showing?How will the user indicate that they are finished? Have you considered the more traditional approach of having the editor popup a dialog or undecorated window in which the data is entered? Something like:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editor
Jim S.

Similar Messages

  • Using a JComboBox within a JPopupMenu

    I have a JPopupMenu in which I'm placing a JComboBox for
    list selection. The problem is that when I click on the JComboBox,
    the original JPopupMenu disappears and only the JComboBox
    popup menu remains.
    Is there a way to keep the original popup menu displayed
    before, during, and after selecting an item in the combo-box
    list?
    Thanks,
    -Andy

    I ended up using a JList instead of a JComboBox and
    it's working now.
    Thanks for the reply.Hi, yours is not a menu in Java GUI apparatus context.
    Use javax.swing.Popup directly.

  • Handling Data in JComboBox added to JTable using Rendrers

    Hi All,
    I have 3 columns with JCombobox with in a table.I have used Rendrers and Editors for handling them.
    Issue:
    In table,3 columns droplist have some values populated initially.When i change item in Column1 Droplist in row 0 ,then i have to dynamically populate values in to Column2 Droplist in "row 0 only".But i see the whole column2 Droplists are populated with the same values as in row0 which should not happen.Each row values should be independent of the other.
    My Implementation:
    Editor Calss:
    public class ComboBoxEditor extends JCombobox {
    // All the default editor method ovverriden here
    Please help me out in fixing this issue.
    Thanks in advance.
    cheers,
    sharath

    Maybe this is what you are looking for:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566133
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Adding a JPopupMenu to a JTabbedPane

    I have been trying for quite a while to accomplish this and I've been unsuccessful thus far.
    I have a program that spawns a JEditorPane that displays html documents containing help information. Before, when another instance of the help command was issued another window would pop up, but I've recently converted this interface to a JTabbedPane instead. I'd like to add the functionality to close a pane individually through a context menu when the user rightclicks on a tab but no luck so far.
    My problem doesn't necessarily deal with getting the correct tab to close at this point, it's getting the menu to display period.
    I mimiced the procedure listed in the following sun tutorial to no avail:
    http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup
    I'm using java 1.4.0_01 on 2k.
    Thanks in advance,
    Justin

    Are you using the new SCROLL_TAB_LAYOUT option? If
    so, you're up against a known bug that isn't going to
    be fixed before the 1.5 release; go back to the
    wrapped layout and see if it works. If that isn't the
    problem, then you'd better post your code.That's what it was -- thanks for the help, hopefully we can get it resolved in the meantime.
    Justin

  • JPopupMenu with JInternalFrame, popup menu doesn't work

    hi, i have this problem, as shown in the sample code at the end of this post.. basically, i have a table, and i added a JPopupMenu onto the table.. the popup menu works well when running the table class, though, when i call the table class in a JInternalFrame environment, the popup menu won't work.. anyone know why?
    ///Basic sample table code, when run this alone, the popup menu will work
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TableBasic extends JPanel
         private JTable table;
         public TableBasic()
              String[] columnNames = { "Date", "String", "Integer", "Boolean" };
              Object[][] data =
                   {  { new Date(), "A", new Integer(1), Boolean.TRUE },
                        { new Date(), "B", new Integer(2), Boolean.FALSE },
                        { new Date(), "C", new Integer(9), Boolean.TRUE },
                        { new Date(), "D", new Integer(4), Boolean.FALSE}
              table = new JTable(data, columnNames)
                   //Returning the Class of each column will allow different
                   //renderers to be used based on Class
                   public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              JScrollPane scrollPane = new JScrollPane(table);
              add(scrollPane);
         public void createPopupMenu()
              JMenuItem menuItem;
              //Create the popup menu.
              JPopupMenu popup = new JPopupMenu();
              menuItem = new JMenuItem("A popup menu item");
              //menuItem.addActionListener(this);
              popup.add(menuItem);
              menuItem = new JMenuItem("Another popup menu item");
              //menuItem.addActionListener(this);
              popup.add(menuItem);
              //Add listener to the text area so the popup menu can come up.
              MouseListener popupListener = new PopupListener(popup);
              table.addMouseListener(popupListener);
         public static void main(String[] args)
              JFrame frame = new JFrame();
              TableBasic table = new TableBasic();
              table.createPopupMenu();
              frame.setContentPane(table);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              //frame.setLocationRelativeTo(null);
              frame.setVisible(true);
         class PopupListener extends MouseAdapter
              JPopupMenu popup;
              PopupListener(JPopupMenu popupMenu)
                   popup = popupMenu;
              public void mousePressed(MouseEvent e)
                   maybeShowPopup(e);
              public void mouseReleased(MouseEvent e)
                   maybeShowPopup(e);
              private void maybeShowPopup(MouseEvent e)
                   if (e.isPopupTrigger())
                        popup.show(e.getComponent(), e.getX(), e.getY());
    ///when integrate the previous table into here, popup menu won't work
    import java.awt.*;
    import javax.swing.*;
    public class InternalFrameBasic
         extends JFrame
         //implements ActionListener
         private JDesktopPane desktop;
         private JInternalFrame menuWindow;
         public static final int desktopWidth = 800;
         public static final int desktopHeight = 700;
         public InternalFrameBasic(String title)
              super(title);
              //Set up the GUI.
              desktop = new JDesktopPane();
              desktop.putClientProperty("JDesktopPane.dragMode", "outline");
              //Because we use pack, it's not enough to call setSize.
              //We must set the desktop's preferred size.
              desktop.setPreferredSize(new Dimension(desktopWidth, desktopHeight));
              setContentPane(desktop);
              createMenuWindow();
              desktop.add(menuWindow); //DON'T FORGET THIS!!!
              Dimension displaySize = menuWindow.getSize();
              menuWindow.setSize(desktopWidth, displaySize.height);
         private void createMenuWindow()
              menuWindow =
                             new JInternalFrame("Event Watcher", true, //resizable
                                                                                                   true, //closable
                                                                                                   false, //not maximizable
                                                                                                   true); //iconifiable
              menuWindow.setContentPane(new TableBasic());
              menuWindow.pack();
              menuWindow.setVisible(true);
          * Create the GUI and show it.  For thread safety,
          * this method should be invoked from the
          * event-dispatching thread.
         private static void createAndShowGUI()
              //Make sure we have nice window decorations.
              //JFrame.setDefaultLookAndFeelDecorated(true);
              //Create and set up the window.
              JFrame frame = new InternalFrameBasic("Example Internal Frame");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args)
              //Schedule a job for the event-dispatching thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        createAndShowGUI();
    }

    table.createPopupMenu();The above line should not be in the main method. It should be in the constructor class of TableBasic.
    You never execute that method in your InternalFrameBasic class to the mouse listener never gets added to the table.

  • Utilisation du Jcombobox

    S'il vous plait;
    j'utilse un JCombo Box pour charger les informations et comment je peux utiliser le meme pour ecrire de dans. Lakami

    My french is bad, so I better write in english than in abominable french.
    A very simple example:
    // initializing the JComboBox
    JComboBox jBox = new JComboBox();
    // adding an item
    jBox.add("Test");
    // an output of the selected Item
    // you always get a Object, as with Vector or ArrayList
    String text = (String) jBox.getSelectedItem();Rommie.

  • No Event from JPopupMenu

    Hallo,
    In my application I added an JPopupMenu that contains MenuItems for a ContextMenu (push the right mouse button to display it).
    It works fine if the JPopupMenu display inside the frame.
    If the JPopupMenu displays with only one pixel or more out of the frame none ActionEvent will be fired.
    Can someone tell me why and knows the solution?
    Kind regards
    Markus

    Hi,
    Nop.

  • JPopupMenu no actionEvent

    Hallo,
    In my application I added a JPopupMenu for a ContextMenu (klick on right Mousebutton to display it).
    It works fine if the JPopMenu display inside the Frame.
    But if the JPopMenu display with only one Pixel out of the Frame there will be none actionEvent fired.
    knows someone a solution

    In order to identify currently selected JTable,do one thing;
    table.addMouseListener();With the help of mouseReleased you may be able to determine the last selected JTable's object.
    Now u have got the source for mouseReleased Event.
    get the selected row by
    table.getSelectedRow();Since u have got the Table and its selected rows, u can do the actions for the table with ur PopupMenu.

  • "Java Applet Window" and keeping PopupMenu inside Applet

    I just added a JPopupMenu to my Applet, and I want to remove the "Java Applet Window" at the bottom. I know this can be done by making sure the PopupMenu stays inside the Applet area. How can I make it stay inside the Applet area?

    Hi Duncan,
    thank you for your answer (on Forms Forum, too :-)
    In the init function I do
    public void init(IHandler handler)
    mHandler = handler;
    super.init(handler);
    // getting the Forms Main class
    formsMain = (Main) mHandler.getApplet();
    // Accessor to the external frame
    formsTopFrame = formsMain.getFrame();
    The constructor does
    optionPane = new JOptionPane( "some text", JOptionPane.INFORMATION_MESSAGE);
    and before the showMessageDialog I put
    formsTopFrame.add(optionPane);
    but with no effect.
    Do you have some more hints?
    Regards,
    Werner

  • Please help! How to add a combobox on a jtable

    Hi, I have seen on google and here many codes to add a combobox in a jtable but none of them seem to work, I need the urgently.
    My problem is that I must add a comboBox or a JComboBox to a cell inside a JTable on a predefined column. It means that on the column 2 I must add diferent comboboxes for eac row. How can I do it, please help.

    The celleditor is the component shown and the cellrenderer is the first render of a component in the cell and dont have to be the same jcombo box?
    The code on ther post does this:?
    returning a diferent combobox for all the cells on the column depending on the row selected, but as long as only one cell can be selected at a time it seems to hace different jcomboboxes added a time?
    Is there anyway to render any combobox with different values, my program must let the user chose the teacher it want to teach a definen subject, so the combo must have the teacher of a subject loaded on a database, the combos are not constants. I guess I can manage to use the way you showed me, but is there anyway to render a combo just by adding it to a cell! maybe doing changes to the tablemodel or things like that?

  • Mnemonics not working on Menu Items

    Hi,
    In my application I am using a JList and added a JPopupmenu to the JList. On mouse-right click on JList item, JPopupmenu is displayed with the Mnemonic characters underlined but the mnemonic keys are not working. When I replaced the mnemonic keys with the Accelerator keys, they are working.
    Is this a bug or known issue or did I go wrong in implementation ?
    Thanks in Advance.
    Anil.

    or did I go wrong in implementation ?Works fine for me.
    If you need further help then you need to create a [url http://www.physci.org/codes/sscce.jsp]Short, Self Contained, Compilable and Executable, Example Program, because I can't guess what you are doing based on the information provided.

  • Help with dropdown menu in JCombo box,Pleaseeeeeee

    Hi,
    I posted earlier but I`II try again. Someone must know how to do this. I have a JComboBox and I want the drop down menu to be a bit wider then the comboBox.
    I tried using this method
    public void setPreferredSize()
              Dimension d = jcbo.getPreferredSize(d);
              jcbo.setPreferredSize(new Dimension(20, d.height));
              jcbo.setPopupWidth(d.width);
    but I recieved a couldn`t resolve symbol error for the last line.
    I imported these into the program]
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    Is there something else I should of imported as well to make this work, or is it another problem all together.Any help would be greatly appreciated.

    Hi , What I want to do is have the dropmenu a bit wider then the comboBox. Here is my code.Please excuse any odd ball mistakes, At this point I have been trying anything.This is an exercise that I have to do fo a java assignment, Hence the weird GUI. In the example pic they gave me.It shows the dropmenu a bit wider than the comboBox, I am sure they through this in to screw with my brain, I have put comment tags Around the stuff I tried to use. Any help with this would be greatly appreciated.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    //import javax.swing.plaf.basic.*;
    public class Exercise9_3 extends JFrame implements ActionListener
         private JTextField nameField;
         private JTextArea nameArea;
         private JButton storeButton;
         private JComboBox jcbo;
         private JPopupMenu popup;
         protected int popupWidth;
         String newline = "\n";
         public Exercise9_3()
              createComponets();
              addComponets();
              setTitle("Exercise9_3");
         private void createComponets ()
              nameField = new JTextField(19);
              nameArea = new JTextArea(10, 15);
              storeButton = new JButton("Store");
              storeButton.addActionListener(this);
              jcbo = new JComboBox();
              jcbo.addActionListener(this);
         /*8public void setPreferredSize()
              Dimension d = jcbo.getPreferredSize(d);
              //jcbo.setPreferredSize(new Dimension(20, d.height));
              //jcbo.setPopupWidth(d.width);
         private void addComponets()
              JPanel p1 = new JPanel();
              p1.setLayout (new FlowLayout());
              p1.add(nameField);
              p1.add(nameArea);
              p1.add(jcbo);
              JPanel p2 = new JPanel();
              p2.setLayout (new FlowLayout());
              p2.add (storeButton);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(p1, BorderLayout.CENTER);
              getContentPane().add(p2, BorderLayout.SOUTH);
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == storeButton)
                   String s = nameField.getText();
                   jcbo.addItem(s);
                   jcbo.setSelectedItem(s);
                   String textArea = s ;
                   String text = nameField.getText();
                   nameArea.append(text + newline);
         nameField.selectAll();
         nameField.setText("");
         nameField.requestFocus();
              if (e.getSource() == jcbo)
    /**retrieve the input as a string*/
    String selectedName = (String)jcbo.getSelectedItem();
    /**set the name that was selected from the ComboBox and add it to textfield*/
    nameField.setText(selectedName);
         public static void main(String [] args)
              Exercise9_3 frame = new Exercise9_3();
              frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              int screenWidth = screenSize.width;
              int screenHeight = screenSize.height;
              // Get dimension of the frame
              Dimension frameSize = frame.getSize();
              int x = (screenWidth - frameSize.width)/2;
              int y = (screenHeight- frameSize.height)/2;
         frame.setLocation(x,y);

  • JList, which item at x,y

    Hi.
    I've a JList component, i've added a JPopupMenu.
    When the user right clicks on an item, i want to know which item has been clicked on.
    Right click doesn't select the item (in win platf.), so i've to determine which item has been pressed.
    How can I do?
    Thanks in advance

    agostino75 wrote:
    Hi.
    I've a JList component, i've added a JPopupMenu.
    When the user right clicks on an item, i want to know which item has been clicked on.
    Right click doesn't select the item (in win platf.), so i've to determine which item has been pressed.
    How can I do?
    Thanks in advanceSo you want to find the list index for a given location ? Maybe the JList API has a method that does that?
    http://java.sun.com/javase/6/docs/api/javax/swing/JList.html

  • Adding an array of objects to a JComboBox

    Hi hope someone can help I have searched the forums and cannot find any previous questions that cover this.
    Basically I want to construct a JComboBox and instead of populating the ComboBox with strings Im wanting to add check boxes.
    First Question can this actually be done?
    Second Question how?
    I have included a sample of the code to show what i mean.
    JCheckBox[] layerChecks = new JCheckBox[numberLayers];
    for(int i =0; i<numberLayers; i++)
    layerChecks[i] = new JCheckBox();
    layerChecks.setText(nameLayers[i]);
    JComboBox layersComboBox = new javax.swing.JComboBox(layerChecks);
    add(layersComboBox);
    Any help is much appreciated.

    Whenever something like this crops up, you should do a double check
    to see of what you are trying to do makes sense.
    I'm not saying it doesn't, but from a user point of view, a combo box
    with checkboxes is something a user hasn't seen before, so they might not like it.
    I've recently done some combo box stuff. What I did was:
    subclass MetalComboBoxUI (and WindowsComboBoxUI and MotifComboBoxUI).
    In the createPopup() method of the UI create a BasicComboPopup (or MotifCalendarPopup). The BasicComboPopup is a subclass of JPopupMenu, that uses a JList so you do a popup.removeAll() to get rid of the list, then add your item(s) to the popup.
    ...works for me !
    infact here is the basic structure. You'll need to modify to make it
    more general purpose.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.plaf.ComboBoxUI;
    import javax.swing.plaf.basic.ComboPopup;
    import javax.swing.plaf.basic.BasicComboPopup;
    import javax.swing.plaf.metal.MetalComboBoxUI;
    import com.sun.java.swing.plaf.motif.MotifComboBoxUI;
    import com.sun.java.swing.plaf.windows.WindowsComboBoxUI;
    public class CheckBoxCombo extends JComboBox {
        public CheckBoxCombo() {
            super();
        public void updateUI() {
            ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this);
            if (cui instanceof MetalComboBoxUI) {
                cui = new MyMetalComboBoxUI();
            } else if (cui instanceof MotifComboBoxUI) {
                cui = new MyMotifComboBoxUI();
            } else if (cui instanceof WindowsComboBoxUI) {
                cui = new MyWindowsComboBoxUI();
            setUI(cui);
         * You probably don't want to populate the popup here...
        protected void setupPopup(BasicComboPopup popup) {
            popup.removeAll();
            popup.add(new JCheckBoxMenuItem("One", false));
            popup.add(new JCheckBoxMenuItem("Two", true));
            popup.add(new JCheckBoxMenuItem("Three", false));
        class MyMetalComboBoxUI extends MetalComboBoxUI {
            protected ComboPopup createPopup() {
                BasicComboPopup popup = new BasicComboPopup(this.comboBox);
                setupPopup(popup);
                return popup;
        class MyWindowsComboBoxUI extends WindowsComboBoxUI {
            protected ComboPopup createPopup() {
                BasicComboPopup popup = new BasicComboPopup(this.comboBox);
                setupPopup(popup);
                return popup;
        class MyMotifComboBoxUI extends MotifComboBoxUI {
            class MotifCalendarPopup extends MotifComboBoxUI.MotifComboPopup {
                public MotifCalendarPopup(JComboBox box) {
                    super(box);
            protected ComboPopup createPopup() {
                MotifCalendarPopup popup =
                        new MotifCalendarPopup(this.comboBox);
                setupPopup(popup);
                return popup;
        public static void main(String[] args) {
            //        String defaultLAF = UIManager.getSystemLookAndFeelClassName();
            //        try {
            //            UIManager.setLookAndFeel(defaultLAF);
            //        } catch (Exception e) {
            //            e.printStackTrace();
            JFrame f = new JFrame();
            final CheckBoxCombo cc = new CheckBoxCombo();
            cc.setEditable(false);
            JPanel enablePanel = new JPanel();
            ButtonGroup buttonGroup = new ButtonGroup();
            JRadioButton b = new JRadioButton(new AbstractAction("Enabled") {
                                                  public void actionPerformed(
                                                          ActionEvent e) {
                                                      cc.setEnabled(true);
            buttonGroup.add(b);
            enablePanel.add(b);
            b.setSelected(true);
            b = new JRadioButton(new AbstractAction("Disabled") {
                                     public void actionPerformed(
                                             ActionEvent e) {
                                         cc.setEnabled(false);
            buttonGroup.add(b);
            enablePanel.add(b);
            f.getContentPane().add(enablePanel, BorderLayout.NORTH);
            f.getContentPane().add(cc);
            f.pack();
            f.show();

  • Adding items in JComboBox - Help

    Hy, I have a JComboBox() and a JTextField().
    when I input a name in the JTextField and clicks on the "Ok" button
    the name is added in the JComboBox().
    What I want is when I click on the "Ok" button, a check is made to see
    whether the name input in the JTextField already exist in the JComboBox().
    If is exist a message is displayed else it is added.
    How to perform the check.
    PLease send me code for doing this.
    thanks

    Hi.
    The JComboBox uses a model to get its hands on the elements to be displayed. Thus you must search the model to see if the string is already contained.
    Use something like this:
        public boolean contains(JComboBox comboBox, String s) {
            int elementCount = comboBox.getModel().getSize();
            for (int i = 0; i < elementCount; i ++) {
                String t = (String)comboBox.getModel().getElementAt(i);
                if (t.equals(s))
                    return true;
            return false;
        }Hope this helps,
    Michael

Maybe you are looking for

  • How can we update the date&time without refreshing the page

    Hi friends, I have a jsp page. In that there is Date and Time. The date and time should be updated for every one minute without refresh the page(dynamically). Its urgent for me Thanks Mallik

  • Multiple emails with their own icons for q10!!!!! And Hide option missing?

    As i understood, it is at this time impossible to have email icon outside HUB. I dont like that because many of us enjoyed having separate email account icons. For multiple reasons. One of them is privacy. If I want to use HUB, but still want to have

  • Z Payment Program to be created

    I have to create a Payment Program for Payment method type "T",this program will b added in F110 (to print the payment advice). I am not sure how to begin with this issue. if anyone has worked on it, please provide some inputs. As in, how should i st

  • How can add a progress bar into script?

    Hi, I got a script for gen pdf I want put a progress bar, and make it working but I don't know where I can put the progress bar and how //===================================================================== var doc = app.documents;  app.findTextPref

  • TP error while adding the Transport Request.

    HI, My server crashed. Restored the backup. In STMS, I am not able to import old Transport Request. While importing  throw the below error. Command: ADDTOBUFFER DEVK900103 DEV U1 pf= DEVELOPMENT\sap   Return code: 0247   Error text: addtobuffer has p