Java 如何在使用glazedList..evenlist时更新组合框
好的,我已经试过了所有的技巧但是我不知道如何更新组合框w/glazedList如果输入来自其他类我试着把值传递给方法,首先声明它为一个字符串..等等..但是没有一个有效..但是如果新项目只是来自同一个类..那么它确实有效..通过点击按钮。。 到目前为止,我得到了这个密码Java 如何在使用glazedList..evenlist时更新组合框,java,combobox,jcombobox,auto-update,glazedlists,Java,Combobox,Jcombobox,Auto Update,Glazedlists,好的,我已经试过了所有的技巧但是我不知道如何更新组合框w/glazedList如果输入来自其他类我试着把值传递给方法,首先声明它为一个字符串..等等..但是没有一个有效..但是如果新项目只是来自同一个类..那么它确实有效..通过点击按钮。。 到目前为止,我得到了这个密码 values = GlazedLists.eventListOf(auto);//auto is an array.. AutoCompleteSupport.install(comboSearch,values);/
values = GlazedLists.eventListOf(auto);//auto is an array..
AutoCompleteSupport.install(comboSearch,values);//comboSearch is the comboBox
//"x" is the value coming from another class.
public void updateCombo(String x){
List<String> item = new ArrayList<>();
item.add(x)
value.addAll(item);
}
values=glazedList.eventListOf(自动)//auto是一个数组。。
安装(组合搜索,值)//comboSearch是组合框
//“x”是来自另一个类的值。
公共void updatembo(字符串x){
列表项=新建ArrayList();
项目.添加(x)
值。添加所有(项目);
}
我希望这些代码足以解释我想问的问题。不可能看到您是如何创建组合框和事件列表的。因此,我将从头开始创建一个简单的示例应用程序,向您展示其要点 以防您不熟悉一般概念,主要要点如下:
- 尽量避免使用标准Java集合(如ArrayList、Vector),并尽快使用
类。排序/过滤/自动完成所带来的所有好处都依赖于EnvivLead基金会,所以设置一个ASAP,然后简单地操作(添加/删除/等等),然后GLZZEDIST管道将负责其余部分。EventList
- 一旦您在
事件列表中获得了对象集合,并且希望利用swing组件,请查看
模块,该模块包含您需要的所有内容。在本例中,您可以在事件列表中使用一个ca.odell.glazedList.swing
-传递,然后将JComboxmodel设置为使用新创建的eventlistcomboxmodel
,从那时起,GlazedList将负责确保列表数据结构和组合框保持同步eventlistcomboxmodel
eventlistcomboxmodel
将列表链接到组合框
请注意以下代码仅针对GlazedList 1.8进行了测试。但我很确定它也可以用1.9或1.7
public class UpdateComboBox {
private JFrame mainFrame;
private JComboBox cboItems;
private EventList<String> itemsList = new BasicEventList<String>();
public UpdateComboBox() {
createGUI();
}
private void createGUI() {
mainFrame = new JFrame("GlazedLists Update Combobox Example");
mainFrame.setSize(600, 400);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton addButton = new JButton("Add Item");
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
itemsList.add("Item " + (itemsList.size()+1));
}
});
// Use a GlazedLists EventComboBoxModel to connect the JComboBox with an EventList.
EventComboBoxModel<String> model = new EventComboBoxModel<String>(itemsList);
cboItems = new JComboBox(model);
JPanel panel = new JPanel(new BorderLayout());
panel.add(cboItems, BorderLayout.NORTH);
panel.add(addButton, BorderLayout.SOUTH);
mainFrame.getContentPane().add(panel);
mainFrame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new UpdateComboBox();
}
});
}
}
公共类更新mbobox{
专用JFrame主机;
私人JComboxCBoItems;
private EventList itemsList=new BasicEventList();
公共更新mbobox(){
createGUI();
}
私有void createGUI(){
mainFrame=new JFrame(“GlazedList更新组合框示例”);
大型机。设置大小(600400);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton addButton=新JButton(“添加项”);
addButton.addActionListener(新ActionListener(){
@凌驾
已执行的公共无效操作(操作事件e){
itemsList.add(“Item”+(itemsList.size()+1));
}
});
//使用GlazedList EventComboBox模型将JComboBox与事件列表连接起来。
EventComboBoxModel=新的EventComboxModel(itemsList);
cboItems=新JCOMBOX(型号);
JPanel panel=newjpanel(newborderlayout());
面板。添加(cboItems,BorderLayout.NORTH);
panel.add(添加按钮,BorderLayout.SOUTH);
mainFrame.getContentPane().add(面板);
mainFrame.setVisible(true);
}
公共静态void main(字符串[]args){
SwingUtilities.invokeLater(新的Runnable(){
@凌驾
公开募捐{
新的updatembobox();
}
});
}
}
无法查看您是如何创建组合框和事件列表的。因此,我将从头开始创建一个简单的示例应用程序,向您展示其要点
以防您不熟悉一般概念,主要要点如下:
- 尽量避免使用标准Java集合(如ArrayList、Vector),并尽快使用
类。排序/过滤/自动完成所带来的所有好处都依赖于EnvivLead基金会,所以设置一个ASAP,然后简单地操作(添加/删除/等等),然后GLZZEDIST管道将负责其余部分。EventList
- 一旦您在
事件列表中获得了对象集合,并且希望利用swing组件,请查看
模块,该模块包含您需要的所有内容。在本例中,您可以在事件列表中使用一个ca.odell.glazedList.swing
-传递,然后将JComboxmodel设置为使用新创建的eventlistcomboxmodel
,从那时起,GlazedList将负责确保列表数据结构和组合框保持同步eventlistcomboxmodel
eventlistcomboxmodel
将列表链接到组合框
请注意以下代码仅针对GlazedList 1.8进行了测试。但我很确定它也可以用1.9或1.7
public class UpdateComboBox {
private JFrame mainFrame;
private JComboBox cboItems;
private EventList<String> itemsList = new BasicEventList<String>();
public UpdateComboBox() {
createGUI();
}
private void createGUI() {
mainFrame = new JFrame("GlazedLists Update Combobox Example");
mainFrame.setSize(600, 400);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton addButton = new JButton("Add Item");
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
itemsList.add("Item " + (itemsList.size()+1));
}
});
// Use a GlazedLists EventComboBoxModel to connect the JComboBox with an EventList.
EventComboBoxModel<String> model = new EventComboBoxModel<String>(itemsList);
cboItems = new JComboBox(model);
JPanel panel = new JPanel(new BorderLayout());
panel.add(cboItems, BorderLayout.NORTH);
panel.add(addButton, BorderLayout.SOUTH);
mainFrame.getContentPane().add(panel);
mainFrame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new UpdateComboBox();
}
});
}
}
公共类更新mbobox{
专用JFrame主机;
私人JComboxCBoItems;
private EventList itemsList=new BasicEventList();
公共更新mbobox(){
createGUI();
}
私有void createGUI(){
mainFrame=new JFrame(“GlazedList更新组合框示例”);
大型机。设置大小(600400);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton addButton=新JButton(“添加项”);
addButton.addActionListener(新ActionListener(){
@凌驾
已执行的公共无效操作(ActionEvent