Example usage for javax.swing.table TableColumn setMinWidth

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

Introduction

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

Prototype

@BeanProperty(description = "The minimum width of the column.")
public void setMinWidth(int minWidth) 

Source Link

Document

Sets the TableColumn's minimum width to minWidth, adjusting the new minimum width if necessary to ensure that 0 <= minWidth <= maxWidth.

Usage

From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java

private void setColumnWidth(TableColumn column, int initial, int max, int min) {
    if (initial != 0) {
        column.setPreferredWidth(initial);
    }/*from www  .j  a  v a  2 s .  co m*/
    if (max != 0) {
        column.setMaxWidth(max);
    }
    if (min != 0) {
        column.setMinWidth(min);
    }
}

From source file:org.openconcerto.task.TodoListPanel.java

private void initTable(int mode) {
    this.t.setBlockRepaint(true);

    this.t.setBlockEventOnColumn(true);
    this.model.setMode(mode);

    this.t.getColumnModel().getColumn(0).setCellRenderer(this.a);
    this.t.getColumnModel().getColumn(0).setCellEditor(this.a);
    this.t.setBlockEventOnColumn(true);
    setIconForColumn(0, this.iconTache);
    setIconForColumn(1, this.iconPriorite);
    this.t.setBlockEventOnColumn(true);

    this.t.getColumnModel().getColumn(1).setCellEditor(this.iconEditor);
    final JTextField textField = new JTextField() {
        @Override//from  www.j  a  v  a2  s. c  om
        public void paint(Graphics g) {
            super.paint(g);
            g.setColor(TodoListPanel.this.t.getGridColor());
            g.fillRect(getWidth() - 19, 0, 1, getHeight());
            g.setColor(new Color(250, 250, 250));
            g.fillRect(getWidth() - 18, 0, 18, getHeight());
            g.setColor(Color.BLACK);
            for (int i = 0; i < 3; i++) {
                int x = getWidth() - 14 + i * 4;
                int y = getHeight() - 5;
                g.fillRect(x, y, 1, 2);
            }
        }
    };
    textField.setBorder(BorderFactory.createEmptyBorder());
    final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(textField);
    textField.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent e) {

        }

        public void mouseEntered(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mousePressed(MouseEvent e) {

        }

        public void mouseReleased(MouseEvent e) {
            if (e.getX() > textField.getWidth() - 19) {
                TodoListElement l = getTaskAt(
                        SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TodoListPanel.this.t));
                TodoListPanel.this.t.editingCanceled(new ChangeEvent(this));
                JFrame f = new JFrame(TM.tr("details"));
                f.setContentPane(new TodoListElementEditorPanel(l));
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setSize(500, 200);
                f.setLocation(50, e.getYOnScreen() + TodoListPanel.this.t.getRowHeight());
                f.setVisible(true);
            }

        }
    });
    this.t.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor);
    this.t.getColumnModel().getColumn(3).setMaxWidth(300);
    this.t.getColumnModel().getColumn(3).setMinWidth(100);

    this.timestampTableCellEditorCreated.stopCellEditing();
    this.timestampTableCellEditorDone.stopCellEditing();
    this.timestampTableCellEditorDeadLine.stopCellEditing();

    if (this.model.getMode() == TodoListModel.EXTENDED_MODE) {
        this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererCreated);
        this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorCreated);

        this.t.getColumnModel().getColumn(4).setCellRenderer(this.timestampTableCellRendererDone);
        this.t.getColumnModel().getColumn(4).setCellEditor(this.timestampTableCellEditorDone);

        this.t.getColumnModel().getColumn(5).setCellRenderer(this.timestampTableCellRendererDeadLine);
        this.t.getColumnModel().getColumn(5).setCellEditor(this.timestampTableCellEditorDeadLine);
    } else {
        this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererDeadLine);
        this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorDeadLine);
    }

    final TableColumn userColumn = this.t.getColumnModel()
            .getColumn(this.t.getColumnModel().getColumnCount() - 1);
    userColumn.setCellRenderer(this.userTableCellRenderer);
    userColumn.setMaxWidth(150);
    userColumn.setMinWidth(100);
    t.setEnabled(false);
    initUserCellEditor(userColumn);

    this.t.setBlockEventOnColumn(false);
    this.t.setBlockRepaint(false);
    this.t.getColumnModel().getColumn(1).setCellRenderer(this.iconRenderer);
    // Better look
    this.t.setShowHorizontalLines(false);
    this.t.setGridColor(new Color(230, 230, 230));
    this.t.setRowHeight(new JTextField(" ").getPreferredSize().height + 4);
    AlternateTableCellRenderer.UTILS.setAllColumns(this.t);
    this.t.repaint();

}

From source file:org.openconcerto.task.TodoListPanel.java

private void setIconForColumn(int i, ImageIcon icon) {

    TableCellRenderer renderer = new JComponentTableCellRenderer(icon);
    TableColumnModel columnModel = this.t.getColumnModel();
    TableColumn column = columnModel.getColumn(i);
    column.setHeaderRenderer(renderer);//from  w w w  .j  a v a2s  . c  om
    column.setMaxWidth(icon.getIconWidth() + 16);
    column.setMinWidth(icon.getIconWidth() + 8);
}

From source file:org.openflexo.technologyadapter.excel.view.ExcelSheetView.java

public ExcelSheetView(ExcelSheet sheet, FlexoController controller) {
    super(new BorderLayout());
    this.sheet = sheet;
    this.controller = controller;
    tableModel = new ExcelSheetTableModel();
    table = new MultiSpanCellTable(tableModel);
    table.setBackground(Color.WHITE);
    table.setShowGrid(true);//from ww  w.j  a v  a  2  s . co m
    table.setGridColor(Color.LIGHT_GRAY);
    table.setRowMargin(0);
    table.getColumnModel().setColumnMargin(0);

    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        TableColumn col = table.getColumnModel().getColumn(i);
        if (i == 0) {
            col.setWidth(25);
            col.setPreferredWidth(25);
            col.setMinWidth(25);
            col.setMaxWidth(100);
            // col.setResizable(false);
            col.setHeaderValue(null);
        } else {
            col.setWidth(sheet.getSheet().getColumnWidth(i - 1) / 40);
            col.setPreferredWidth(sheet.getSheet().getColumnWidth(i - 1) / 40);
            col.setHeaderValue("" + Character.toChars(i + 64)[0]);
        }
    }
    table.setDefaultRenderer(Object.class, new ExcelSheetCellRenderer());
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    add(new JScrollPane(table), BorderLayout.CENTER);

    cellIdentifier = new JTextField(6);
    cellIdentifier.setEditable(false);
    cellIdentifier.setHorizontalAlignment(SwingConstants.CENTER);
    cellValue = new JTextField();
    cellValue.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            valueEditedForSelectedCell(cellValue.getText());
        }
    });
    /*cellValue.getDocument().addDocumentListener(new DocumentListener() {
       @Override
       public void removeUpdate(DocumentEvent e) {
    valueEditedForSelectedCell(cellValue.getText());
       }
            
       @Override
       public void insertUpdate(DocumentEvent e) {
    valueEditedForSelectedCell(cellValue.getText());
       }
            
       @Override
       public void changedUpdate(DocumentEvent e) {
    valueEditedForSelectedCell(cellValue.getText());
       }
    });*/
    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(cellIdentifier, BorderLayout.WEST);
    topPanel.add(cellValue, BorderLayout.CENTER);
    add(topPanel, BorderLayout.NORTH);

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            selectionChanged();
        }
    });
    table.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
            selectionChanged();
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
        }

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }
    });

    updateRowHeights();

    validate();

    /*for (Object p : sheet.getSheet().getWorkbook().getAllPictures()) {
       System.out.println("Picture: " + p);
    }
            
    System.out.println("class = " + sheet.getSheet().getClass());
            
    if (sheet.getSheet() instanceof HSSFSheet) {
            
       List<HSSFShape> shapes = ((HSSFSheet) sheet.getSheet()).getDrawingPatriarch().getChildren();
       System.out.println("Prout=" + shapes);
       for (int i = 0; i < shapes.size(); i++) {
    System.out.println("hop avec " + shapes.get(i));
    if (shapes.get(i) instanceof HSSFPicture) {
       HSSFPicture pic = (HSSFPicture) shapes.get(i);
       HSSFPictureData picdata = ((HSSFSheet) sheet.getSheet()).getWorkbook().getAllPictures().get(pic.getPictureIndex());
            
       System.out.println("New picture found : " + pic);
       System.out.println("Anchor : " + pic.getAnchor());
       System.out.println("file extension " + picdata.suggestFileExtension());
            
       // int pictureIndex = this.newSheet.getWorkbook().addPicture( picdata.getData(), picdata.getFormat());
            
       // this.newSheet.createDrawingPatriarch().createPicture((HSSFClientAnchor)pic.getAnchor()r, pictureIndex);
            
    }
            
       }
    }*/
}

From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java

public void addColumn(final TableColumn column) {
    stopEditing();/*from  w  ww. j  a v  a  2  s.c o  m*/
    if (column.getHeaderValue() == null) {
        final int modelColumn = column.getModelIndex();
        final String columnName = getModel().getColumnName(modelColumn);
        if (modelColumn == 0) {
            column.setResizable(false);
            column.setHeaderValue(columnName);
            column.setPreferredWidth(30);
            column.setMaxWidth(30);
            column.setMinWidth(30);
        } else {
            final Class columnType = getModel().getColumnClass(modelColumn);
            column.setHeaderValue(new TypedHeaderInformation(columnType, columnName));
        }
    }
    getColumnModel().addColumn(column);

}

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/*  w  w  w . j a v a2s. 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);
    }
}