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 8572933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:08:13+00:00 2026-06-11T19:08:13+00:00

I made a combobox but some of the elements are wider than the width

  • 0

I made a combobox but some of the elements are wider than the width of my box. So I tried to add a horizontal scrolpane and the only I could see is a scrolpane with a combobox inside!
Certanly something I do wrong. So here is my code without the jscrolpane.

    issuerdocumentJComboBox=new JComboBox<>(issuermodel);//the compo box
    issuerdocumentJComboBox.setBounds(430, 120, 100, 30);
    searchDocumentesJPanel.add(issuerdocumentJComboBox);   

How can I add to the combobox a horizontal scrollpane?
Thank you!

  • 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-06-11T19:08:15+00:00Added an answer on June 11, 2026 at 7:08 pm

    It is possible!! Here’s a little program I wrote to show my solution:

    import java.awt.Component;
    import java.awt.Dimension;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.plaf.basic.BasicComboBoxEditor;
    
    public class TestComboScroll {
    
        public static void main(String[] args) {
            JFrame frame = new JFrame("Scroll inside Combo");
            JComboBox combobox = new JComboBox();
    
            combobox.addItem("");
            combobox.addItem("Item1");
            combobox.addItem("Item2 Item2 Item2 Item2 Item2 Item2 Item2 Item2 Item2 Item2 Item2 Item2 Item2 Item2");
            combobox.addItem("Item3");
    
            combobox.setEditor(new MyEditor());
            combobox.setEditable(true);
    
            combobox.setPreferredSize(new Dimension(200, 50));
            frame.add(combobox);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    
        static class MyEditor extends BasicComboBoxEditor{
            JScrollPane scroller = new JScrollPane();
            //NOTE: editor is a JTextField defined in BasicComboBoxEditor
    
            public MyEditor(){
                super();
                scroller.setViewportView(editor); 
                scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            }
    
            /** Return a JScrollPane containing the JTextField instead of the JTextField **/
            @Override
            public Component getEditorComponent() {
                return scroller;
            }
    
            /** Override to create your own JTextField. **/
            @Override
            protected JTextField createEditorComponent() {
                JTextField editor = new JTextField();
                editor.setBorder(null);
                /*editor.setEditable(false); //If you want it not to be editable */
                return editor;
            }
        }
    }
    

    The approach is to create a custom ComboBoxEditor that displays the JTextField editor in a scroll pane (easier to just extend BasicComboBoxEditor).
    The getEditorComponent() function is then overridden to return the scroll pane instead of the text field.

    These two overidden functions are called internally when you call combobox.setEditor(new MyEditor()) so don’t worry if you can’t see it being used.

    Here’s a screenshot of the program showing an element wider than combobox:
    screenshot

    GOODLUCK!! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to bind some BindingList to ComboBox control in my WPF App. But,
I made some HeaderTemplate for Combobox.GroupStyle in order to display items in groups. And
Made a custom obj called Item with some string fields and one float. .h
I made a dll in c# but i need to export the functions. Is
I made a Web service in which I have a function to count some
I'v got a combobox that I created as a user control(it's actually made up
I've made an extended ComboBox based on the one ExtJs features. That's all fine.
We currently have a WPF application showing some 3D schema and we have made
I made a very simple component to replace any component (e.g. a comboBox) on
When I create (try to create) a ComboBox in WiX, the box receives its

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.