Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Java remove JComboBox arrow button

I added a JComboBox from the palette using netbeans IDE and populated it with contents from mysql database. I also added autocomplete functionality using swingx-all-1.6.5-1

method for populating combobox

    public void doPopulateCombo(){
    Connection con = Functions.ConnectToDB();
    try {
        Statement stmt = con.createStatement();
        String sqlQuery = "select * from products";
        ResultSet rs = stmt.executeQuery(sqlQuery);

        while(rs.next()){
            String product_name = rs.getString("Product_Name");
            cboProducts.addItem(product_name);
        }
        con.close();
        cboProducts.setSelectedIndex(-1);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Error populating combo box\n"+e.toString(),
                "Error",JOptionPane.ERROR_MESSAGE);
    }
}

How do I remove the combobox's arrow button so that it appears like a textbox?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The best I can come up with is putting it into a JPanel that's slightly smaller than it, but depending on the L&F that's not really the best way to do it. Alternatively you could make a class that extends JComboBox, overrides the paint(Graphics g) method and from there calls the paint method of a textbox with the same dimensions. At least, I think you could do that, if you wanted to. Do note that you'd have to update what's in the textbox each time the user selects an option.

over 4 years ago · Santiago Trujillo Report

0

A hacky way to fix this would be to create your own implementation of BasicComboBoxUI and override createArrowButton()

public class NoArrowJComboBoxUI extends BasicComboBoxUI {

    @Override
    protected JButton createArrowButton() {
        JButton btn = new JButton();
        btn.setPreferredSize(new Dimension(0,0));
        btn.setVisible(false);
        return btn;
    }

}

Then in your existing code:

    cboProducts.setSelectedIndex(-1);
    cboProducts.setUI(new NoArrowJComboBoxUI());

This implementation should not interfere with autocomplete behavior, however, I haven't tested it myself with autocomplete so I can't say that with certainty.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!