我的 Swing GUI 中有一个 jComboBox,用于填充 SQL 数据库中的值。
一切看起来都很好,但是当我运行应用程序时,我的组合框出现了,例如 [Black ...],旁边有 3 个点。
请指教如何删除 3 个点。
编辑: 为我的 jComboBox 添加了代码和它的图像
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);
}
}
按照上图,我给它设置了相当长的宽度,但我无法删除 3 个点。
最佳答案
您可能没有在 GUI 上提供足够的物理空间来显示数据。为您的组合框留出更多水平空间(即,使其更长)。
更新
As per the image above, I've given quite a long width to it yet I'm unable to remove the 3 dots.
根据您添加的屏幕截图,我的猜测 是数据问题。一些 jdbc 驱动程序会给你空格填充的字符串,直到列的长度,即使数据要短得多。例如,定义为 char(10) 且其中具有值“A”的列可能会从您的查询返回为
"A ". If this is the case, trim the strings before adding them to the combo:
String depth = rs.getString("depth").trim();
此外,正如 mKorbel 所建议的,您可以为您的组合设置原型(prototype):
// if you're using strings, and the max length will be 10
comboDepth.setPrototypeDisplayValue("1234567890");
请记住,如果空格导致数据比您预期的长,填充空格(如您的屏幕截图所示)仍然是个问题。
关于Java Swing - 带有三个点的组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14224109/