Example usage for javax.swing JComboBox revalidate

List of usage examples for javax.swing JComboBox revalidate

Introduction

In this page you can find the example usage for javax.swing JComboBox revalidate.

Prototype

public void revalidate() 

Source Link

Document

Supports deferred automatic layout.

Usage

From source file:storybook.model.EntityUtil.java

@SuppressWarnings("unchecked")
public static void fillAutoCombo(MainFrame mainFrame, AutoCompleteComboBox autoCombo,
        AbstractEntityHandler entityHandler, String text, String methodName) {
    try {/*from   w  w  w  .ja v a 2  s .c  om*/
        JComboBox combo = autoCombo.getJComboBox();
        combo.removeAllItems();
        BookModel model = mainFrame.getBookModel();
        Session session = model.beginTransaction();
        SbGenericDAOImpl<?, ?> dao = entityHandler.createDAO();
        dao.setSession(session);
        Method m = dao.getClass().getMethod(methodName, (Class<?>[]) null);
        List<Object> items = (List<Object>) m.invoke(dao);
        model.commit();
        for (Object item : items) {
            if (item == null || ((item instanceof String) && (((String) item).isEmpty()))) {
                continue;
            }
            combo.addItem(item);
        }
        combo.addItem("");
        combo.getModel().setSelectedItem(text);
        combo.revalidate();
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        SbApp.error("EntityUtil.copyEntityProperties()", e);
    }
}

From source file:storybook.model.EntityUtil.java

@SuppressWarnings("unchecked")
public static void fillEntityCombo(MainFrame mainFrame, JComboBox combo, AbstractEntityHandler entityHandler,
        AbstractEntity entity, boolean isNew, boolean addEmptyItem) {
    combo.removeAllItems();//from www  .  j av a  2s  .c  o m
    ListCellRenderer renderer = entityHandler.getListCellRenderer();
    if (renderer != null) {
        combo.setRenderer(renderer);
    }
    int i = 0;
    if (addEmptyItem) {
        ++i;
        combo.addItem("");
    }
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    SbGenericDAOImpl<?, ?> dao = entityHandler.createDAO();
    dao.setSession(session);
    @SuppressWarnings("unchecked")
    List<AbstractEntity> entities = (List<AbstractEntity>) dao.findAll();
    for (AbstractEntity entity2 : entities) {
        session.refresh(entity2);
        combo.addItem(entity2);
        if (entity != null) {
            if (entity.getId().equals(entity2.getId())) // don't use combo.setSelectedItem(entity) here
            // leads to a "no session" exception for tag links
            {
                combo.setSelectedIndex(i);
            }
        }
        ++i;
    }
    combo.revalidate();
    model.commit();
}