Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6728393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:09:53+00:00 2026-05-26T10:09:53+00:00

In other words, I want JTable to drop-down a combo-box whenever user types in

  • 0

In other words, I want JTable to drop-down a combo-box whenever user types in a cell that has a JComboBox (or any other JComboBox-based cell-editor) editor associated to it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:09:54+00:00Added an answer on May 26, 2026 at 10:09 am

    Basically, you have to install an appropriate listener on the combo and open the popup explicitly. First candidate for “appropriate” is an AncestorListener, which invokes showing the popup in its ancestorAdded method.

    Unfortunately that doesn’t seem to be the whole story: works if the table’s surrenderFocus property is false. If it is true works only for not-editable combos. After some digging, the reason for the not-working part turns out to be an internal focustransfer (from the combo to the textfield) after the popup is opened by the ancestorListener. In that case, we need a second listener which opens the popup once the editor’s editingComponent got the focus permanently.

    Multiple listeners routinely step onto each other’s feet, so best to not install both permanently but do it on each call to getEditorComp, and let them uninstall themselves once they showed the popup. Below is a working example of how-to do it, just beware: it’s not formally tested!

    public static class DefaultCellEditorX extends DefaultCellEditor {
        private AncestorListener ancestorListener;
        private PropertyChangeListener focusPropertyListener;
    
        public DefaultCellEditorX(JComboBox comboBox) {
            super(comboBox);
        }
    
        /** 
         * Overridden to install an appriate listener which opens the
         * popup when actually starting an edit.
         * 
         * @inherited <p>
         */
        @Override
        public Component getTableCellEditorComponent(JTable table,
                Object value, boolean isSelected, int row, int column) {
            super.getTableCellEditorComponent(table, value, isSelected, row, column);
            installListener(table);
            return getComponent();
        }
    
        /**
         * Shows popup.
         */
        protected void showPopup() {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    getComponent().setPopupVisible(true);
                }
            });
        }
    
    
        /**
         * Dynamically install self-uninstalling listener, depending on JComboBox
         * and JTable state. 
         * @param table
         */
        private void installListener(JTable table) {
            if (getComponent().isEditable() && table.getSurrendersFocusOnKeystroke()) {
                installKeyboardFocusListener();
            } else {
                installAncestorListener();
            }
        }
    
        private void installAncestorListener() {
            if (ancestorListener == null) {
                ancestorListener = new AncestorListener() {
    
                    @Override
                    public void ancestorAdded(AncestorEvent event) {
                        getComponent().removeAncestorListener(ancestorListener);
                        showPopup();
                    }
    
                    @Override
                    public void ancestorRemoved(AncestorEvent event) {
                    }
    
                    @Override
                    public void ancestorMoved(AncestorEvent event) {
                    }
    
                };
            }
            getComponent().addAncestorListener(ancestorListener);
        }
    
        private void installKeyboardFocusListener() {
            if (focusPropertyListener == null) {
                focusPropertyListener = new PropertyChangeListener() {
    
                    @Override
                    public void propertyChange(PropertyChangeEvent evt) {
                        LOG.info("property: " + evt.getPropertyName());
                        if (focusManager().getPermanentFocusOwner() != 
                            getComponent().getEditor().getEditorComponent()) return;
                        focusManager()
                           .removePropertyChangeListener("permanentFocusOwner", focusPropertyListener);
                        showPopup();
                    }
    
                };
            }
            focusManager().addPropertyChangeListener("permanentFocusOwner", focusPropertyListener);
        }
    
        /**
         * Convience for less typing.
         * @return
         */
        protected KeyboardFocusManager focusManager() {
            return KeyboardFocusManager.getCurrentKeyboardFocusManager();
        }
    
        /** 
         * Convenience for type cast.
         * @inherited <p>
         */
        @Override
        public JComboBox getComponent() {
            return (JComboBox) super.getComponent();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check for duplicated words right next to each other, but even
In other words, can fn() know that it is being used as $var =
Something like this: http://perl.plover.com/yak/regex/samples/slide083.html In other words I want to match successfully on {
I would like to create a TRANSLUCENT grouped table view cell. In other words
I have a user control that exposes a property of type ImageSource. I want
I want to copy text from a JTable 's cell to the clipboard, making
I want to create an asp.net web forms website that has a products page.
I want to gray non-editable cell in JTable. I'm using such TableCellRenderer: TableColumn column
I want to define a method interceptor in a Java program in other words
I want to change form attributes with JQuery. In other browsers it works fine,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.