English 中文(简体)
敏感的jcombo 案
原标题:case sensitive jcombobox

我的问题是一小.。 我正在使用<代码>Editable JComboBox。 它可能含有敏感案件。 例如,它可能有<代码>Item1和>项目1。 因此,就我而言,这两个项目应区别对待。

但问题是,这两个项目也一样对待。 无论我选择的项目是什么,它总是选择第一个项目(Item1)。 我在谷歌搜索,但找不到任何解决办法。 因此,我在这里发言。

http://www.ohchr.org。

//loading of Items
jdcbmItemType = new javax.swing.DefaultComboBoxModel(ItemTypeHandler.getItemTypeComboData(MainFrame.companyId));

private void jcbItemTypeMouseReleased(MouseEvent evt)
{
    if (jcbItemType.getSelectedIndex() != -1)
    {
        loadItemTypeDetails(((ItemObject) jcbItemType.getSelectedItem()).getId());
    }
    else
    {
        resetFields();
    }
}

public static Vector<ItemObject> getItemTypeComboDataV(BigInteger companyId, BigInteger categoryId, boolean addFirstElement, TriState deleted) throws ExceptionWrapper, EJBException
{
    try
    {            
        return (Vector<ItemObject>)lookupItemTypeFacade().getItemTypeComboData(companyId, categoryId, addFirstElement, deleted);
    } catch (ExceptionWrapper exceptionWrapper)
    {
        throw exceptionWrapper;
    } catch (EJBException ejbEx)
    {
        throw ejbEx;
    } catch (Exception ex)
    {
        throw new ExceptionWrapper(ex.getMessage());
    }
}

习俗 某个领域为<代码>BigInteger,另一个领域为<编码>。

getItemTypeComboData正在正常运作。 因此,您可以假设收到<代码>清单。 项目Object from here and it will nicely 2007, it to Vector<ItemObject>

jcbItemType.getS selected Index( 总是将<代码>Item1和>项目1的同一索引退还。 但它回收了<代码>项目2的不同索引。

我知道,如果我能使用<条码>项目国家编码活动,那将更好。 但就我而言,我可以不使用。 但是,我的问题是,MouseReleased FocusLost为不同名称拼写而做的罚款,但与不同情况不同。 我确实感到 st。

www.un.org/spanish/ecosoc 提问的另一个方式:

<代码>MouseReleased或FocusLost

如何解决这一问题?

Thanks.

最佳回答

这里是我的SSCCE和该作品的罚款,如果这不是你所期待的话,那么,你将担任以下职务:


import javax.swing.*;
import java.awt.event.*;

public class ComboBoxTest {

    JComboBox combo;
    JTextField txt;

    public static void main(String[] args) {
        new ComboBoxTest();
    }

    public ComboBoxTest() {
        String items[] = {"Item1", "item1"};
        JFrame frame = new JFrame("JComboBox Case-sensitivity Test");
        JPanel panel = new JPanel();
        combo = new JComboBox(items);
        combo.setEditable(true);

        txt = new JTextField(10);
        panel.add(combo);
        panel.add(txt);
        frame.add(panel);
        combo.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent ie) {
                String str = (String) combo.getSelectedItem();
                txt.setText(str);
            }
        });
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 100);
        frame.setVisible(true);
    }
}
问题回答

I think you are doing like this :-

String[] items = {"item1", "item2"};
JComboBox cb = new JComboBox(items);
cb.setEditable(true);

Now you have to access the JCombobox elements which you have insert into this as in array form like this:- MyItemListener actionListener = new MyItemListener(); cb.addItemListener(actionListener);

class MyItemListener implements ItemListener {
// This method is called only if a new item has been selected.
public void itemStateChanged(ItemEvent evt) {
    JComboBox cb = (JComboBox)evt.getSource();

    // Get the affected item
    Object item = evt.getItem();

    if (evt.getStateChange() == ItemEvent.SELECTED) {
        // Item was just selected
    } else if (evt.getStateChange() == ItemEvent.DESELECTED) {
        // Item is no longer selected
    }
    }
 }

After adding the itemListener you can do your different tasks with individual JCombobox Item

引证工作......

利用行动Listener()来抓点击......然后利用SonSgneItem()来抓点击JComboBox的项目。

try this,

页: 1

myComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent ie) {
            String str = (String) myComboBox.getSelectedItem();
           System.out.println(str);
        }




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签