简体   繁体   中英

Java Swing - Combobox with three dots

I have a jComboBox in my Swing GUI, filling the value from my SQL Database.

All looks fine but when I run the application, my combobox appeared eg [Black ...] with the 3 dots to the side.

Please advice how can I remove the 3 dots.

Edited: Added code for my jComboBox and a image of it

    public void fillTankDepth()
{

    String fill = "Select * from swdepth";
    try{
        ps = conn.prepareStatement(fill);
        rs = ps.executeQuery();

        while(rs.next()){
            String depth = rs.getString("depth");
            comboDepth.addItem(depth);

                        }
    }
    catch(Exception e){
    JOptionPane.showMessageDialog(null, e);    
    }
 }

在此输入图像描述

As per the image above, I've given quite a long width to it yet I'm unable to remove the 3 dots.

You likely aren't providing enough physical room on your GUI to display the data. Make more horizontal room for your combobox (ie, make it longer).

UPDATE

As per the image above, I've given quite a long width to it yet I'm unable to remove the 3 dots.

Looking at the screenshot you added, my guess is that it's a data problem. Some jdbc drivers will give you space-padded strings out to the length of the column, even if the data is much shorter. For example, a column defined as char(10) that has the value "A" in it may come back from your query as

"A         "
. If this is the case, trim the strings before adding them to the combo:

 String depth = rs.getString("depth").trim(); 

Also, as suggested by mKorbel, you can set the prototype for your combo:

 // if you're using strings, and the max length will be 10 comboDepth.setPrototypeDisplayValue("1234567890"); 

Keep in mind, the padded spaces (as your screenshot suggests) will still be a problem if the spaces are causing the data to be longer than what you're expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM