Example usage for javax.swing JTable convertColumnIndexToView

List of usage examples for javax.swing JTable convertColumnIndexToView

Introduction

In this page you can find the example usage for javax.swing JTable convertColumnIndexToView.

Prototype

public int convertColumnIndexToView(int modelColumnIndex) 

Source Link

Document

Maps the index of the column in the table model at modelColumnIndex to the index of the column in the view.

Usage

From source file:com.sshtools.common.ui.PreferencesStore.java

/**
 *
 *
 * @param table/*from  w ww.  j ava2 s  . c o  m*/
 * @param pref
 * @param defaultWidths
 *
 * @throws IllegalArgumentException
 */
public static void restoreTableMetrics(JTable table, String pref, int[] defaultWidths) {
    //  Check the table columns may be resized correctly
    if (table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF) {
        throw new IllegalArgumentException("Table AutoResizeMode must be JTable.AUTO_RESIZE_OFF");
    }

    //  Restore the table column widths and positions
    for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
        try {
            table.moveColumn(table.convertColumnIndexToView(getInt(pref + ".column." + i + ".position", i)), i);
            table.getColumnModel().getColumn(i)
                    .setPreferredWidth(getInt(pref + ".column." + i + ".width",
                            (defaultWidths == null) ? table.getColumnModel().getColumn(i).getPreferredWidth()
                                    : defaultWidths[i]));
        } catch (NumberFormatException nfe) {
        }
    }
}

From source file:org.nuclos.client.common.Utils.java

/**
 * sets the input focus to a certain collectable component in a LayoutML mask.
 * @param eafnInitialFocus entity name and field name of the component that is to receive to focus. The entity name is
 * null, if the component is not in a subform.
 * @param clctcompprovider map of all collectable components in the layout
 * @param mpsubformctl map of all subformcontrollers
 * @param frame frame of the layout (for possible warning dialogs only)
 * @param bShowWarnings displays warnings for components not found for focussing
 * @precondition eafnInitialFocus != null
 *///from   w w w  .j  a  v a2  s  . c  o  m
public static void setInitialComponentFocus(EntityAndFieldName eafnInitialFocus,
        final CollectableComponentsProvider clctcompprovider,
        final Map<String, ? extends SubFormController> mpsubformctl, final MainFrameTab frame,
        final boolean bShowWarnings) {

    final String sInitialFocusEntityName = eafnInitialFocus.getEntityName();
    final String sInitialFocusFieldName = eafnInitialFocus.getFieldName();

    // Must be invoked later, else focus is not set with compound components like LOVs
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                if (sInitialFocusEntityName == null) {
                    if (sInitialFocusFieldName != null) {
                        final Collection<CollectableComponent> collclctcomp = clctcompprovider
                                .getCollectableComponentsFor(sInitialFocusFieldName);
                        if (collclctcomp.isEmpty()) {
                            if (bShowWarnings) {
                                final String sMessage = SpringLocaleDelegate.getInstance().getMessage(
                                        "ClientUtils.1",
                                        "Das angegebene Feld f\u00fcr den initialen Fokus existiert nicht.");
                                JOptionPane
                                        .showMessageDialog(
                                                frame, sMessage, SpringLocaleDelegate.getInstance()
                                                        .getMessage("ClientUtils.2", "Hinweis"),
                                                JOptionPane.WARNING_MESSAGE);
                            }
                        } else {
                            final CollectableComponent clctcomp = collclctcomp.iterator().next();
                            final JComponent compFocus = clctcomp.getFocusableComponent();
                            compFocus.requestFocusInWindow();
                        }
                    }
                } else {
                    final SubFormController subformctl = mpsubformctl.get(sInitialFocusEntityName);
                    if (subformctl != null) {
                        final SubForm.SubFormTableModel subformtblmdl = (SubForm.SubFormTableModel) subformctl
                                .getSubForm().getJTable().getModel();

                        final JTable tbl = subformctl.getSubForm().getJTable();
                        final int iColumn = tbl.convertColumnIndexToView(
                                subformtblmdl.findColumnByFieldName(sInitialFocusFieldName));
                        if (iColumn != -1) {
                            if (subformtblmdl.getRowCount() > 0) {
                                tbl.editCellAt(0, iColumn);

                                Component comp = tbl.getCellEditor().getTableCellEditorComponent(tbl,
                                        tbl.getValueAt(0, iColumn), true, 0, iColumn);

                                // Special case for multiline text editor components
                                if (comp instanceof JScrollPane) {
                                    comp = ((JScrollPane) comp).getViewport().getView();
                                }
                                comp.requestFocusInWindow();
                            }
                        } else {
                            if (bShowWarnings) {
                                final String sMessage = SpringLocaleDelegate.getInstance().getMessage(
                                        "ClientUtils.3",
                                        "Das angegebene Feld in der Entit\u00e4t f\u00fcr den initialen Fokus existiert nicht.");
                                JOptionPane
                                        .showMessageDialog(
                                                frame, sMessage, SpringLocaleDelegate.getInstance()
                                                        .getMessage("ClientUtils.2", "Hinweis"),
                                                JOptionPane.WARNING_MESSAGE);
                            }
                        }
                    } else {
                        if (bShowWarnings) {
                            final String sMessage = SpringLocaleDelegate.getInstance().getMessage(
                                    "ClientUtils.4",
                                    "Die angegebene Entit\u00e4t f\u00fcr den initialen Fokus existiert nicht.");
                            JOptionPane.showMessageDialog(frame, sMessage,
                                    SpringLocaleDelegate.getInstance().getMessage("ClientUtils.2", "Hinweis"),
                                    JOptionPane.WARNING_MESSAGE);
                        }
                    }
                }
            } catch (Exception e) {
                LOG.error("setInitialComponentFocus failed: " + e, e);
            }
        }
    });
}