Example usage for javax.swing.table TableColumn setPreferredWidth

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

Introduction

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

Prototype

@BeanProperty(description = "The preferred width of the column.")
public void setPreferredWidth(int preferredWidth) 

Source Link

Document

Sets this column's preferred width to preferredWidth.

Usage

From source file:org.piraso.ui.base.ExportDialog.java

private void initTable() {
    TableColumn selectionColumn = jtable.getColumnModel().getColumn(0);
    TableColumn boldOption = jtable.getColumnModel().getColumn(1);

    selectionColumn.setHeaderValue("");
    selectionColumn.setPreferredWidth(30);
    selectionColumn.setMaxWidth(30);/*from  w w w  .  ja  v  a2s.  c o m*/
    selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class));
    selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class));

    boldOption.setHeaderValue("Option");
    boldOption.setPreferredWidth(200);

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}

From source file:org.piraso.ui.base.ProfilesDialog.java

private void initTable() {
    TableColumn nameColumn = jtable.getColumnModel().getColumn(0);
    TableColumn urlColumn = jtable.getColumnModel().getColumn(1);
    TableColumn watchColumn = jtable.getColumnModel().getColumn(2);

    nameColumn.setHeaderValue("Name");
    urlColumn.setPreferredWidth(210);
    nameColumn.setMaxWidth(235);/* w  w w  .  j  a  v a2 s.c  om*/

    urlColumn.setHeaderValue("Logging URL");
    urlColumn.setPreferredWidth(220);
    urlColumn.setMaxWidth(700);

    watchColumn.setHeaderValue("Watch Address");
    watchColumn.setMaxWidth(200);

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.getTableHeader().setReorderingAllowed(false);
}

From source file:org.piraso.ui.base.SaveMonitorInstanceDialog.java

private void initTable() {
    TableColumn selectionColumn = jtable.getColumnModel().getColumn(0);
    TableColumn boldOption = jtable.getColumnModel().getColumn(1);

    selectionColumn.setHeaderValue("");
    selectionColumn.setPreferredWidth(30);
    selectionColumn.setMaxWidth(30);//from  w  w w. j ava  2  s.co  m
    selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class));
    selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class));

    boldOption.setHeaderValue("Request URL");
    boldOption.setPreferredWidth(200);

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}

From source file:org.piraso.ui.log4j.Log4jPreferenceDialog.java

private void initTable() {
    TableColumn loggerColumn = jtable.getColumnModel().getColumn(0);
    TableColumn descriptionColumn = jtable.getColumnModel().getColumn(1);

    loggerColumn.setHeaderValue("Logger");
    loggerColumn.setPreferredWidth(120);

    descriptionColumn.setHeaderValue("Description");
    descriptionColumn.setPreferredWidth(300);

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);//from w  w w.j  av  a  2 s  .  co m
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}

From source file:org.piraso.ui.sql.SQLViewTopComponent.java

private void initTable() {
    TableColumn numColumn = table.getColumnModel().getColumn(0);
    TableColumn methodColumn = table.getColumnModel().getColumn(1);
    TableColumn typeColumn = table.getColumnModel().getColumn(2);
    TableColumn valueColumn = table.getColumnModel().getColumn(3);

    numColumn.setHeaderValue("");
    numColumn.setMaxWidth(30);//from   w  w  w .  ja va 2  s  .  c  om
    numColumn.setCellRenderer(new AlignableTableCellRendererImpl(SwingConstants.RIGHT, false, true));

    methodColumn.setHeaderValue("Method");
    methodColumn.setPreferredWidth(300);

    typeColumn.setHeaderValue("Type");
    typeColumn.setPreferredWidth(200);

    valueColumn.setHeaderValue("Value");
    valueColumn.setPreferredWidth(200);
}

From source file:org.sleuthkit.autopsy.ingest.IngestProgressSnapshotPanel.java

private void customizeComponents() {
    threadActivitySnapshotsTable.setModel(threadActivityTableModel);
    jobTable.setModel(jobTableModel);/*w  w w  . j a  va  2  s  .  c  om*/
    moduleTable.setModel(moduleTableModel);

    int width = snapshotsScrollPane.getPreferredSize().width;
    for (int i = 0; i < threadActivitySnapshotsTable.getColumnCount(); ++i) {
        TableColumn column = threadActivitySnapshotsTable.getColumnModel().getColumn(i);
        switch (i) {
        case 0:
            column.setPreferredWidth(((int) (width * 0.02)));
            break;
        case 1:
            column.setPreferredWidth(((int) (width * 0.20)));
            break;
        case 2:
            column.setPreferredWidth(((int) (width * 0.15)));
            break;
        case 3:
            column.setPreferredWidth(((int) (width * 0.35)));
            break;
        case 4:
            column.setPreferredWidth(((int) (width * 0.18)));
            break;
        case 5:
            column.setPreferredWidth(((int) (width * 0.10)));
            break;
        }
    }

    threadActivitySnapshotsTable.setFillsViewportHeight(true);
}

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

public static void makeTableColumnWidthFit(JTable jTable, int col, int margin, boolean locking) {
    // strategy - get max width for cells in column and
    // make that the preferred width
    TableColumnModel columnModel = jTable.getColumnModel();
    int maxwidth = 0;

    for (int row = 0; row < jTable.getRowCount(); row++) {
        TableCellRenderer rend = jTable.getCellRenderer(row, col);
        Object value = jTable.getValueAt(row, col);
        Component comp = rend.getTableCellRendererComponent(jTable, value, false, false, row, col);

        maxwidth = Math.max(comp.getPreferredSize().width + margin, maxwidth);
    } // for row/* www. ja  v  a  2 s  .  c  o  m*/

    TableColumn column = columnModel.getColumn(col);
    TableCellRenderer headerRenderer = column.getHeaderRenderer();
    if (headerRenderer == null) {
        headerRenderer = jTable.getTableHeader().getDefaultRenderer();
    }
    Object headerValue = column.getHeaderValue();
    Component headerComp = headerRenderer.getTableCellRendererComponent(jTable, headerValue, false, false, 0,
            col);

    maxwidth = Math.max(maxwidth, headerComp.getPreferredSize().width + margin);
    column.setPreferredWidth(maxwidth);
    if (locking) {
        // User will not able to adjust the width manually.
        column.setMinWidth(maxwidth);
        column.setMaxWidth(maxwidth);
    }
}

From source file:org.zaproxy.zap.extension.ascan.PolicyAllCategoryPanel.java

/**
 * This method initializes tableTest//from   ww w  . ja va2  s .  com
 *
 * @return javax.swing.JTable
 */
private JTable getTableTest() {
    if (tableTest == null) {
        tableTest = new JTable();
        tableTest.setModel(getAllCategoryTableModel());
        tableTest.setRowHeight(DisplayUtils.getScaledSize(18));
        tableTest.setIntercellSpacing(new java.awt.Dimension(1, 1));
        tableTest.setAutoCreateRowSorter(true);

        //Default sort by name (column 0)
        List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(1);
        sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
        tableTest.getRowSorter().setSortKeys(sortKeys);

        for (int i = 0; i < tableTest.getColumnCount() - 1; i++) {
            TableColumn column = tableTest.getColumnModel().getColumn(i);
            column.setPreferredWidth(width[i]);
        }

        JComboBox<String> jcb1 = new JComboBox<>();
        jcb1.addItem(""); // Always show a blank one for where they are not all the same
        for (AlertThreshold level : AlertThreshold.values()) {
            jcb1.addItem(Constant.messages.getString("ascan.policy.level." + level.name().toLowerCase()));
        }

        tableTest.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcb1));

        JComboBox<String> jcb2 = new JComboBox<>();
        jcb2.addItem(""); // Always show a blank one for where they are not all the same
        for (AttackStrength level : AttackStrength.values()) {
            jcb2.addItem(Constant.messages.getString("ascan.policy.level." + level.name().toLowerCase()));
        }

        tableTest.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(jcb2));
    }

    return tableTest;
}

From source file:org.zaproxy.zap.extension.customFire.PolicyAllCategoryPanel.java

/**
 * This method initializes tableTest/*  w  w w  . java  2s . c  o  m*/
 *
 * @return javax.swing.JTable
 */
private JTable getTableTest() {
    if (tableTest == null) {
        tableTest = new JTable();
        tableTest.setModel(getAllCategoryTableModel());
        tableTest.setRowHeight(DisplayUtils.getScaledSize(18));
        tableTest.setIntercellSpacing(new java.awt.Dimension(1, 1));
        tableTest.setAutoCreateRowSorter(true);

        //Default sort by name (column 0)
        List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(1);
        sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
        tableTest.getRowSorter().setSortKeys(sortKeys);

        for (int i = 0; i < tableTest.getColumnCount() - 1; i++) {
            TableColumn column = tableTest.getColumnModel().getColumn(i);
            column.setPreferredWidth(width[i]);
        }

        JComboBox<String> jcb1 = new JComboBox<>();
        jcb1.addItem(""); // Always show a blank one for where they are not all the same
        for (AlertThreshold level : AlertThreshold.values()) {
            jcb1.addItem(Constant.messages
                    .getString("customFire.custom.policy.level." + level.name().toLowerCase()));
        }

        tableTest.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcb1));

        JComboBox<String> jcb2 = new JComboBox<>();
        jcb2.addItem(""); // Always show a blank one for where they are not all the same
        for (AttackStrength level : AttackStrength.values()) {
            jcb2.addItem(Constant.messages
                    .getString("customFire.custom.policy.level." + level.name().toLowerCase()));
        }

        tableTest.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(jcb2));
    }

    return tableTest;
}

From source file:org.zaproxy.zap.extension.httppanel.view.paramtable.HttpPanelParamTableView.java

private void init() {
    // Table//from w w  w  . j av  a 2s  . c o  m
    table = new JTable();
    table.setName("");
    table.setModel(httpPanelTabularModel);
    table.setGridColor(java.awt.Color.gray);
    table.setIntercellSpacing(new java.awt.Dimension(1, 1));
    table.setRowHeight(DisplayUtils.getScaledSize(18));

    // Issue 954: Force the JTable cell to auto-save when the focus changes.
    // Example, edit cell, click OK for a panel dialog box, the data will get saved.
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    // Set standard row width's
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setPreferredWidth(70);
    column.setWidth(70);
    column.setMaxWidth(70);
    if (table.getColumnCount() == 4) {
        column = table.getColumnModel().getColumn(3);
        column.setPreferredWidth(150);
        column.setWidth(150);
        column.setMaxWidth(150);
    }

    // Main panel
    mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(new JScrollPane(table), BorderLayout.CENTER);
}