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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:04:39+00:00 2026-06-01T20:04:39+00:00

I have this following combo box, where i am able to create my combo

  • 0

I have this following combo box, where i am able to create my combo box with items etc, but the look is not same as JTextField. How can i make JCombobox look same like JTextField?

enter image description here

MyComboBox.java:

import java.awt.Color;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicComboBoxUI;

public class MyComboBox extends JComboBox {
  public MyComboBox(String[] name) {
    Border border = BorderFactory.createEmptyBorder(11, 11, 11, 11);
    JComboBox cb = new JComboBox(name);
    cb.setUI(new BasicComboBoxUI() {
        @Override
        protected JButton createArrowButton() {
            return new JButton() {
                    @Override
                    public int getWidth() {
                            return 0;
                    }
            };
        }
    });

    setModel(cb.getModel());    
    setOpaque(false);
    setBorder(new LineBorder(Color.black, 1, true));
    //setBackground(Color.white);
    setVisible(true); 


  }
//  public void paintComponent(Graphics g) {
//      super.paintComponent(g);                
//      g.setColor(new Color(red, green, blue) );
//      g.fillOval(125, 125, 50, 50);
//  }  
}
  • 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-01T20:04:40+00:00Added an answer on June 1, 2026 at 8:04 pm
    • best of all could be use Look and Feels

    • JComboBox has two states, JComboBox can be Editable and Non_Editable (default)

    • without CustomUI (as example by @aterai), but Look and Feel sensitive, only for Metal Look and Feel

    enter image description here

    import java.awt.*;
    import java.util.Vector;
    import javax.swing.*;
    import javax.swing.UIManager;
    import javax.swing.plaf.ColorUIResource;
    import javax.swing.plaf.metal.MetalComboBoxButton;
    
    public class MyComboBox {
    
        private Vector<String> listSomeString = new Vector<String>();
        private JComboBox someComboBox = new JComboBox(listSomeString);
        private JComboBox editableComboBox = new JComboBox(listSomeString);
        private JComboBox non_EditableComboBox = new JComboBox(listSomeString);
        private JFrame frame;
    
        public MyComboBox() {
            listSomeString.add("-");
            listSomeString.add("Snowboarding");
            listSomeString.add("Rowing");
            listSomeString.add("Knitting");
            listSomeString.add("Speed reading");
    //
            someComboBox.setPrototypeDisplayValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            someComboBox.setFont(new Font("Serif", Font.BOLD, 16));
            someComboBox.setEditable(true);
            someComboBox.getEditor().getEditorComponent().setBackground(Color.YELLOW);
            ((JTextField) someComboBox.getEditor().getEditorComponent()).setBackground(Color.YELLOW);
    //        
            editableComboBox.setPrototypeDisplayValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            editableComboBox.setFont(new Font("Serif", Font.BOLD, 16));
            editableComboBox.setEditable(true);
            JTextField text = ((JTextField) editableComboBox.getEditor().getEditorComponent());
            text.setBackground(Color.YELLOW);
            JComboBox coloredArrowsCombo = editableComboBox;
            Component[] comp = coloredArrowsCombo.getComponents();
            for (int i = 0; i < comp.length; i++) {
                if (comp[i] instanceof MetalComboBoxButton) {
                    MetalComboBoxButton coloredArrowsButton = (MetalComboBoxButton) comp[i];
                    coloredArrowsButton.setBackground(null);
                    break;
                }
            }
    //        
            non_EditableComboBox.setPrototypeDisplayValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            non_EditableComboBox.setFont(new Font("Serif", Font.BOLD, 16));
    //
            frame = new JFrame();
            frame.setLayout(new GridLayout(0, 1, 10, 10));
            frame.add(someComboBox);
            frame.add(editableComboBox);
            frame.add(non_EditableComboBox);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocation(100, 100);
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            UIManager.put("ComboBox.background", new ColorUIResource(Color.yellow));
            UIManager.put("JTextField.background", new ColorUIResource(Color.yellow));
            UIManager.put("ComboBox.selectionBackground", new ColorUIResource(Color.magenta));
            UIManager.put("ComboBox.selectionForeground", new ColorUIResource(Color.blue));
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    MyComboBox aCTF = new MyComboBox();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following combo box which sets the number of images displayed per
I have a combo-box with following configuration. { fieldLabel:'Service', xtype:'combo', displayField: 'srvcDesc', store: storeServiceCodeVar,
This must be a misunderstanding from my side, but I have the following: I
I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2,
I have this following setup, a textarea named with some data in it that
I have this following code, here CssClass is of the String type. <asp:Panel ID=Panel1
I have this following numpy matrix that I want to sort in ascending order
I have this following code which will return all the current semesters. How do
I have following this blog in setting Xvfb in my ubuntu environment: http://corpocrat.com/2008/08/19/how-to-install-xvfb-x11-server-in-linux-server/ So
Never thought I'd have this problem :) The following snippet of code works in

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.