我有JCombobox很多项目,首先它们是一个NULL价值
打开组合框时,所有项目都有正常高度,但不是第一个,它是一个非常薄的条带.这很难被点击,因为看起来什么都没有(但它存在,你可以选择它).
问题是,如何让这个项目的高度与其他项目相同?
更多信息:
JCombobox.setPrototypeDisplayValue()普通的字符串,如"XXXXX"或其中一个正常项目,但这会改变宽度而不是高度.JCombobox通过ObjectToStringConverter子类用空String("")表示:org.jdesktop.swingx.autocomplete.AutoCompleteDecorator.decorate
(combobox, ConfigurableToStringConverter.INSTANCE);
提前致谢
我正在尝试获取JComboBox对象的位置(作为int),生成ComboBox并拥有这样的动作侦听器
for (int d=0; d<i; d++)
{
titulos.addItem(listaPraBox[d]);
}
ActionListener comboListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
ItemSelectable is =(ItemSelectable)actionEvent.getSource();
objectoseleccionado = selectedString(is);
DeskMetodos.listaTexto(objectoseleccionado);
}
};
titulos.addActionListener(comboListener);
Run Code Online (Sandbox Code Playgroud)
执行
static private String selectedString(ItemSelectable is) {
Object selected[] = is.getSelectedObjects();
return ((selected.length == 0) ? "null" : (String)selected[0]);
}
Run Code Online (Sandbox Code Playgroud)
但我希望所选对象的位置通过该int从另一个数组中获取字符串.
这甚至可能吗?通过我所做的搜索,甚至没有提到这一点.
我搜索并发现了很多不同的东西,但没有一个真正有助于得到我想要的东西.我有两个JComboBox,用户可以在其中选择不同的时间.比如说8:00和17:30.现在我希望能够显示这些时间之间的差异,所以在这种情况下它将是9.5.我希望它在9.5,而不是9:30.但我的代码是9.3,因为它只是将我的字符串转换为double.
任何帮助都会很棒
public void displaytotal() {
Object sunBobj, sunEobj, mon, tues, wed, thur, fri, sat;
double totalD;
sunBobj = jComboBox1.getSelectedItem();
sunEobj = jComboBox2.getSelectedItem();
String sunB = sunBobj.toString();
String sunE = sunEobj.toString();
try {
double sundB = Double.parseDouble(sunB.replace(":", "."));
double sundE = Double.parseDouble(sunE.replace(":", "."));
totalD = ((sundE - sundB)) * 24;
String totalS = "" + totalD;
jLabel17.setText(totalS);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个JComboBox组件:
ho2Combo = new JComboBox();
ho2Combo.setLocation(x, y);
ho2Combo.setSize(w, h);
ho2Combo.setFont(comboFont);
ho2Combo.setModel(new DefaultComboBoxModel(Format.model(0))); //this fills up the combobox
ho2Combo.setSelectedIndex(0);
ho2Combo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
ho2ComboItemStateChanged(evt);
}
});
add(ho2Combo);
Run Code Online (Sandbox Code Playgroud)
我很想拥有没有滚动条的组合框!我怎么能达到这个目的?请帮忙!谢谢!
我有一个String数组,然后我将它添加到一个可编辑的JComboBox中.
用户可以从选择中选择他/她的名字,或者只是输入他/她的名字(如果不在选项中).
如何将用户输入放入新的字符串变量中?
String [] chooseName = { Mark, John, Allison, Jessica };
JComboBox combo = new JComboBox (chooseName);
combo.setEditable(true);
String chosenName = /* how do i place what the user inputed here? */
Run Code Online (Sandbox Code Playgroud) 我在向JComboBox编辑器添加按钮时遇到困难,我成功添加了一个按钮但是我遇到了一些问题,例如当我第一次进入编辑器时,动作执行事件被触发是不可接受的,另一个是我无法获取文本类型.
结果:

问题:

@Override
public Component getEditorComponent() {
return panel;
}
Run Code Online (Sandbox Code Playgroud)
这是问题所在,如果我返回,panel.jtexfield我只会得到一个没有按钮的文本字段,那么这里的诀窍是什么?
这是我的代码
import Store.util.DatabaseHelper;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import org.hibernate.HibernateException;
import org.netbeans.lib.awtextra.AbsoluteLayout;
public class NewComboTest extends JFrame {
private ArrayList<Object> shopCart = new ArrayList<Object>();
private JComboBox cb;
private static final Object[] comboContents = {
"First", "Second", "Third", "Fourth", "Fifth"
};
public NewComboTest() {
super("New Combo Test");
setLayout(null);
cb = new JComboBox();
cb.setRenderer(new NewComboRenderer());
cb.setEditor(new NewComboEditor());
cb.setEditable(true);
cb.setSize(new …Run Code Online (Sandbox Code Playgroud) 您好我有以下代码,以查看JComboBox中的项是否是类(Persoon)的实例.
public class ItemChangeListener implements ItemListener {
Persoon selectedPerson;
RekeningApp app;
PersoonView view;
public ItemChangeListener(PersoonView view) {
this.view = view;
}
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
Object item = event.getItem();
System.out.println("Itemchangelistener " + item);
// do something with object
if(item instanceof Persoon) {
System.out.println("Instance");
this.selectedPerson = (Persoon) item;
view.setOverzicht(this.selectedPerson);
} else {
this.selectedPerson = null;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
item的输出是persoon.name变量的值.所以JComboBox中的项目实际上是字符串.
这就是JComboBox列表的设置方式.
personenList.addItem(persoon.getNaam());
我的问题是..如何检查这个Persoon对象是否存在并且与JComboBox中的相同?
目前我正在填充我的JComboBox:
countryBox = new JComboBox(countryList.toArray(new String[countryList.size()]));
Run Code Online (Sandbox Code Playgroud)
但是,在使用我的程序时countryList,我希望以不同的方式填充我的JComboBox.我尝试使用该操作来更改我的JComboBox:
countryBox.addActionListener(new ActionListener() {
countryBox = new JComboBox(countryList.toArray(new String[countryList.size()]));
}
Run Code Online (Sandbox Code Playgroud)
但是,它并没有改变它的价值.对我来说,countryBox似乎预先填充了之前的数据.任何建议我能做什么?
我感谢你的回答!
我在我的一个Java swing应用程序中有一个搜索字段.我想保存搜索框标题的空间,并在其中放入搜索图标,将其描述为搜索字段.这应该与Facebook搜索领域非常相似.
所以,我的问题是,有没有办法实现这样的事情?作为初学者,我的想法是无效的.任何建议/帮助对我都有积极作用.Editable JComboBox editable jcomboboxJava
谢谢
所以我有这个班级"会员":
package pkgData;
import java.io.Serializable;
public class Member implements Comparable<Member>, Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
private String city;
public Member(String nameOfMember,String location) {
super();
this.name = nameOfMember;
this.city=location;
}
public String getNameOfMember() {
return name;
}
public String getLocationOfMember() {
return city;
}
public void setNameOfMember(String nameOfMember) {
this.name = nameOfMember;
}
@Override
public String toString() {
return name +", " + city;
}
@Override
public int compareTo(Member o) {
int …Run Code Online (Sandbox Code Playgroud)