Example usage for javax.swing.table TableColumn getWidth

List of usage examples for javax.swing.table TableColumn getWidth

Introduction

In this page you can find the example usage for javax.swing.table TableColumn getWidth.

Prototype

public int getWidth() 

Source Link

Document

Returns the width of the TableColumn.

Usage

From source file:ThreadViewer.java

public ThreadViewer() {

    JTable table = new JTable(tableModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    TableColumnModel colModel = table.getColumnModel();
    int numColumns = colModel.getColumnCount();

    for (int i = 0; i < numColumns - 1; i++) {
        TableColumn col = colModel.getColumn(i);

        col.sizeWidthToFit();/*from  w  w  w . j  av  a  2  s . c om*/
        col.setPreferredWidth(col.getWidth() + 5);
        col.setMaxWidth(col.getWidth() + 5);
    }

    JScrollPane sp = new JScrollPane(table);

    setLayout(new BorderLayout());
    add(sp, BorderLayout.CENTER);
}

From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java

@Override
public boolean saveSettings(Element element) {
    element.addAttribute("horizontalScroll", String.valueOf(table.isHorizontalScrollEnabled()));

    saveFontPreferences(element);/*  www . j  a  v  a  2  s .  co  m*/

    Element columnsElem = element.element("columns");
    if (columnsElem != null) {
        element.remove(columnsElem);
    }
    columnsElem = element.addElement("columns");

    final List<TableColumn> visibleTableColumns = table.getColumns();
    final List<Table.Column> visibleColumns = new ArrayList<>();
    for (TableColumn tableColumn : visibleTableColumns) {
        visibleColumns.add((Table.Column) tableColumn.getIdentifier());
    }

    List<TableColumn> columns = table.getColumns(true);
    Collections.sort(columns, new Comparator<TableColumn>() {
        @SuppressWarnings("SuspiciousMethodCalls")
        @Override
        public int compare(TableColumn col1, TableColumn col2) {
            if (col1 instanceof TableColumnExt && !((TableColumnExt) col1).isVisible()) {
                return 1;
            }
            if (col2 instanceof TableColumnExt && !((TableColumnExt) col2).isVisible()) {
                return -1;
            }
            int i1 = visibleColumns.indexOf(col1.getIdentifier());
            int i2 = visibleColumns.indexOf(col2.getIdentifier());
            return Integer.compare(i1, i2);
        }
    });

    for (TableColumn column : columns) {
        Element colElem = columnsElem.addElement("column");
        colElem.addAttribute("id", column.getIdentifier().toString());

        int width = column.getWidth();
        colElem.addAttribute("width", String.valueOf(width));

        if (column instanceof TableColumnExt) {
            Boolean visible = ((TableColumnExt) column).isVisible();
            colElem.addAttribute("visible", visible.toString());
        }
    }

    if (table.getRowSorter() != null) {
        TableColumn sortedColumn = table.getSortedColumn();
        List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys();
        if (sortedColumn != null && !sortKeys.isEmpty()) {
            columnsElem.addAttribute("sortColumn", String.valueOf(sortedColumn.getIdentifier()));
            columnsElem.addAttribute("sortOrder", sortKeys.get(0).getSortOrder().toString());
        }
    }

    return true;
}

From source file:nz.govt.natlib.ndha.manualdeposit.CMSSearchResults.java

private void formWindowClosing(java.awt.event.WindowEvent evt) { // NOPMD
    theFormControl.setExtra(SPLIT_NAME, splitMain.getDividerLocation());
    for (int i = 0; i < tblResults.getColumnModel().getColumnCount(); i++) {
        final TableColumn col = tblResults.getColumnModel().getColumn(i);
        final String colName = "Col" + i;
        theFormControl.setExtra(colName, col.getWidth());
    }/*  w w w  .java2  s.c  o m*/
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void closeForm(java.awt.event.WindowEvent evt) {
    boolean doClose = true;
    if (depositPresenter.jobsRunning()) {
        String message = "You currently have jobs outstanding which will be automatically reloaded the next time this application runs\n\nDo you wish to close?";
        if (!confirm(message)) {
            doClose = false;//from   ww  w .  j a  v  a2 s.c  om
        }
    }
    if (doClose) {
        if (theUserGroupData.isIncludeNoCMSOption() || theUserGroupData.isIncludeProducerList()
                || theUserGroupData.isIncludeCMS2Search() || theUserGroupData.isIncludeCMS1Search()) {
            theFormControl.setExtra(SPLIT_IE_ATTR, splitAddIE.getDividerLocation());
        }
        theFormControl.setExtra(SPLIT_MAIN_ATTR, splitMain.getDividerLocation());
        theFormControl.setExtra(SPLIT_MAIN_DETAIL_ATTR, splitMainDetail.getDividerLocation());
        theFormControl.setExtra(SPLIT_MAIN_RIGHT_ATTR, splitMainRight.getDividerLocation());
        TableColumn col = tblDetail.getColumnModel().getColumn(0);
        theFormControl.setExtra(META_DATA_COL_1_ATTR, col.getWidth());
        col = tblDetail.getColumnModel().getColumn(1);
        theFormControl.setExtra(META_DATA_COL_2_ATTR, col.getWidth());
        MultiSplitLayout.Split model = (MultiSplitLayout.Split) mspJobQueue.getMultiSplitLayout().getModel();
        MultiSplitLayout.Divider divider = (MultiSplitLayout.Divider) model.getChildren().get(1);
        Rectangle bounds = divider.getBounds();
        theFormControl.setExtra(JOB_QUEUE_DIVIDER_1_ATTR, bounds.y);
        divider = (MultiSplitLayout.Divider) model.getChildren().get(3);
        bounds = divider.getBounds();
        theFormControl.setExtra(JOB_QUEUE_DIVIDER_2_ATTR, bounds.y);
        divider = (MultiSplitLayout.Divider) model.getChildren().get(5);
        bounds = divider.getBounds();
        theFormControl.setExtra(JOB_QUEUE_DIVIDER_3_ATTR, bounds.y);
        divider = (MultiSplitLayout.Divider) model.getChildren().get(7);
        bounds = divider.getBounds();
        theFormControl.setExtra(JOB_QUEUE_DIVIDER_4_ATTR, bounds.y);
        theFormControl.closing(evt);
        System.exit(0);
    }
}

From source file:org.omegat.gui.align.AlignPanelController.java

/**
 * Reloads the beads with the current settings. The loading itself takes place on a background thread.
 * Calls {@link #updatePanel(AlignPanel, AlignMenuFrame)} afterwards.
 * /*from www  . j  av  a2 s  .  com*/
 * @param panel
 * @param frame
 */
private void reloadBeads() {
    if (loader != null) {
        loader.cancel(true);
    }
    phase = Phase.ALIGN;
    panel.progressBar.setVisible(true);
    panel.continueButton.setEnabled(false);
    panel.controlsPanel.setVisible(false);
    loader = new SwingWorker<List<MutableBead>, Object>() {
        @Override
        protected List<MutableBead> doInBackground() throws Exception {
            return aligner.alignImpl().filter(o -> !isCancelled()).map(MutableBead::new)
                    .collect(Collectors.toList());
        }

        @Override
        protected void done() {
            List<MutableBead> beads = null;
            try {
                beads = get();
            } catch (CancellationException ex) {
                // Ignore
            } catch (Exception e) {
                Log.log(e);
                JOptionPane.showMessageDialog(panel, OStrings.getString("ALIGNER_ERROR_LOADING"),
                        OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE);
            }
            panel.continueButton.setEnabled(true);
            panel.progressBar.setVisible(false);
            panel.comparisonComboBox
                    .setModel(new DefaultComboBoxModel<>(aligner.allowedModes.toArray(new ComparisonMode[0])));

            String distanceValue = null;
            if (beads != null) {
                double avgDist = MutableBead.calculateAvgDist(beads);
                distanceValue = StringUtil.format(OStrings.getString("ALIGNER_PANEL_LABEL_AVGSCORE"),
                        avgDist == Long.MAX_VALUE ? "-" : String.format("%.3f", avgDist));
                panel.table.setModel(new BeadTableModel(beads));
                for (int i = 0; i < BeadTableModel.COL_SRC; i++) {
                    TableColumn col = panel.table.getColumnModel().getColumn(i);
                    col.setMaxWidth(col.getWidth());
                }
                modified = false;
            }
            panel.averageDistanceLabel.setText(distanceValue);

            updatePanel();
        }
    };
    loader.execute();
}

From source file:org.yccheok.jstock.gui.IndicatorScannerJPanel.java

public boolean saveGUIOptions() {
    if (Utils.createCompleteDirectoryHierarchyIfDoesNotExist(
            org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config") == false) {
        return false;
    }/*w ww.jav  a 2  s  .  c  o  m*/

    final GUIOptions.JTableOptions jTableOptions = new GUIOptions.JTableOptions();

    final int count = this.jTable1.getColumnCount();
    for (int i = 0; i < count; i++) {
        final String name = this.jTable1.getColumnName(i);
        final TableColumn column = jTable1.getColumnModel().getColumn(i);
        jTableOptions
                .addColumnOption(GUIOptions.JTableOptions.ColumnOption.newInstance(name, column.getWidth()));
    }

    final GUIOptions guiOptions = new GUIOptions();
    guiOptions.addJTableOptions(jTableOptions);

    File f = new File(org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config" + File.separator
            + "indicatorscannerjpanel.xml");
    return org.yccheok.jstock.gui.Utils.toXML(guiOptions, f);
}

From source file:org.yccheok.jstock.gui.JStock.java

private boolean _saveGUIOptions() {
    if (Utils.createCompleteDirectoryHierarchyIfDoesNotExist(
            org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config") == false) {
        return false;
    }// w w w.j  a v a  2  s .  c o m

    final GUIOptions.JTableOptions jTableOptions = new GUIOptions.JTableOptions();

    final int count = this.jTable1.getColumnCount();
    for (int i = 0; i < count; i++) {
        final String name = this.jTable1.getColumnName(i);
        final TableColumn column = jTable1.getColumnModel().getColumn(i);
        jTableOptions
                .addColumnOption(GUIOptions.JTableOptions.ColumnOption.newInstance(name, column.getWidth()));
    }

    final GUIOptions guiOptions = new GUIOptions();
    guiOptions.addJTableOptions(jTableOptions);

    File f = new File(
            org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config" + File.separator + "mainframe.xml");
    return Utils.toXML(guiOptions, f);
}

From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java

public boolean saveGUIOptions() {
    if (Utils.createCompleteDirectoryHierarchyIfDoesNotExist(
            org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config") == false) {
        return false;
    }/* w w  w  .j ava2s  . c o m*/

    final GUIOptions guiOptions = new GUIOptions();

    final org.jdesktop.swingx.JXTreeTable[] treeTables = { buyTreeTable, sellTreeTable };

    for (org.jdesktop.swingx.JXTreeTable treeTable : treeTables) {
        final javax.swing.table.JTableHeader jTableHeader = treeTable.getTableHeader();
        final JTable jTable = jTableHeader.getTable();
        final GUIOptions.JTableOptions jTableOptions = new GUIOptions.JTableOptions();

        final int count = jTable.getColumnCount();
        for (int i = 0; i < count; i++) {
            final String name = jTable.getColumnName(i);
            final TableColumn column = jTable.getColumnModel().getColumn(i);
            jTableOptions.addColumnOption(
                    GUIOptions.JTableOptions.ColumnOption.newInstance(name, column.getWidth()));
        }

        guiOptions.addJTableOptions(jTableOptions);
    }

    guiOptions.addDividerLocation(jSplitPane1.getDividerLocation());

    File f = new File(org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config" + File.separator
            + "portfoliomanagementjpanel.xml");
    return org.yccheok.jstock.gui.Utils.toXML(guiOptions, f);
}

From source file:ua.com.fielden.platform.example.swing.egi.EgiExample.java

private void addTotalsFooterTo(final EntityGridInspector egi, final JPanel topPanel) {
    //   final JPanel panel = new JPanel(new MigLayout("insets 0", "[]", "[]0[]push[]"));
    //   panel.add(egi.getTableHeader(), "grow, wrap");
    //   panel.add(egi, "grow, wrap");

    final JScrollPane scrollPane = new JScrollPane(egi);
    topPanel.add(scrollPane, "grow, wrap");

    final JPanel footer = new JPanel(new MigLayout("nogrid, insets 0"));
    //   footer.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    final List<JComponent> totalsComponents = new ArrayList<JComponent>();
    for (int i = 0; i < egi.getColumnCount(); i++) {
        final TableColumn column = egi.getColumnModel().getColumn(i);
        final JComponent totalsComponent = i % 2 == 0 ? new JTextField("totals " + i) : new JLabel();
        totalsComponent.setPreferredSize(new Dimension(column.getPreferredWidth(), 30));

        footer.add(totalsComponent, "grow");
        totalsComponents.add(totalsComponent);
    }/*  w w w.java  2s  .c  o m*/

    final JScrollPane footerPane = new JScrollPane(footer, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    topPanel.add(footerPane, "grow, wrap, h 40::");
    topPanel.add(scrollPane.getHorizontalScrollBar(), "grow, wrap");

    scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        @Override
        public void adjustmentValueChanged(final AdjustmentEvent e) {
            footerPane.getViewport().setViewPosition(new Point(e.getValue(), 0));
        }
    });

    egi.getColumnModel().addColumnModelListener(new TableColumnModelListener() {
        @Override
        public void columnAdded(final TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(final ChangeEvent e) {
            final TableColumn column = egi.getTableHeader().getResizingColumn();
            if (column != null) {
                final JComponent totalsComponent = totalsComponents
                        .get(egi.convertColumnIndexToView(column.getModelIndex()));
                totalsComponent.setPreferredSize(new Dimension(column.getWidth(), totalsComponent.getHeight()));
                footer.revalidate();
            }
        }

        @Override
        public void columnMoved(final TableColumnModelEvent e) {
            final JComponent fromComponent = totalsComponents.get(e.getFromIndex());
            totalsComponents.set(e.getFromIndex(), totalsComponents.get(e.getToIndex()));
            totalsComponents.set(e.getToIndex(), fromComponent);

            footer.removeAll();
            for (int i = 0; i < egi.getColumnCount(); i++) {
                footer.add(totalsComponents.get(i), "grow, gap 0 0 0 0");
            }
            footer.revalidate();
        }

        @Override
        public void columnRemoved(final TableColumnModelEvent e) {
        }

        @Override
        public void columnSelectionChanged(final ListSelectionEvent e) {
        }
    });
    //
    //   return panel;
}