Package javax.swing.table

Examples of javax.swing.table.TableCellRenderer


     *
     * @param column to be resized
     * @param table containing the column
     */
    public static void fixSize(TableColumn column, JTable table) {
        TableCellRenderer rndr;
        rndr = column.getHeaderRenderer();
        if (rndr == null){
            rndr = table.getTableHeader().getDefaultRenderer();
        }
        Component c = rndr.getTableCellRendererComponent(
                table, column.getHeaderValue(), false, false, -1, column.getModelIndex());
        int width = c.getPreferredSize().width+10;
        column.setMaxWidth(width);
        column.setPreferredWidth(width);
        column.setResizable(false);       
View Full Code Here


          }

          @Override
          public TableCellRenderer getRenderer(final IssueNote note)
          {
            return new TableCellRenderer()
            {
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus,
                int row, int column)
              {
                noteInfoPanel.updateNote(note);
                return noteInfoPanel;
              }
            };
          }
        },
        new ColumnInfo<IssueNote, String>("2")
        {
          public String valueOf(IssueNote note)
          {
            return note.getContent();
          }

          @Override
          public void setValue(IssueNote note, String value)
          {
            note.setContent(value);
          }

          @Override
          public boolean isCellEditable(IssueNote note)
          {
            return isEditable(note);
          }

          @Override
          public TableCellRenderer getRenderer(IssueNote note)
          {
            final JTextArea textArea = new JTextArea();
            textArea.setWrapStyleWord(true);
            textArea.setLineWrap(true);
            textArea.setBackground(UIUtil.getPanelBackground());

            return new TableCellRenderer()
            {
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus,
                int row, int column)
              {
View Full Code Here

        Rectangle cellRect = table.getCellRect(rowIndex, columnIndex, false);
        return cellRect;
    }

    public Component getRendererComponent() {
        TableCellRenderer cellRenderer = table.getCellRenderer(rowIndex, columnIndex);
        Component component = table.prepareRenderer(cellRenderer, rowIndex, columnIndex);
        return component;
    }
View Full Code Here

            }
        );
        setDefaultEditor(RatingMetadataEntry.RatingObject.class, ratingEditor);

        // Setup the default renderer and also a specialized rating renderer.
        TableCellRenderer renderer = new MetadataTableCellRenderer();
        setDefaultRenderer(Object.class, renderer);

        TableCellRenderer ratingRenderer = new RatingTableCellRenderer();
        setDefaultRenderer(
            RatingMetadataEntry.RatingObject.class, ratingRenderer
        );
        // setRowHeight(15);
        // setRowMargin(10);
View Full Code Here

    final LayoutManager      lay;
    final JTable        table;
    final AbstractTableModel  tm;
    final SortedTableModel    stm;
    final JTableHeader      th;
    final TableCellRenderer    tcr;
    final JScrollPane      scroll;
    final JTextArea        lbTextArea;
    final Box          b;
    final AbstractButton    ggPlus, ggMinus;
View Full Code Here

    TableColumn column = null;
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;
    Object[] longValues = model.longValues;
    TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();
    for (int i = 0; i < 5; i++) {
      column = table.getColumnModel().getColumn(i);
      comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
      headerWidth = comp.getPreferredSize().width;
      comp = table.getDefaultRenderer(model.getColumnClass(i)).getTableCellRendererComponent(table, longValues[i],
          false, false, 0, i);
      cellWidth = comp.getPreferredSize().width;
      column.setPreferredWidth(Math.max(headerWidth, cellWidth));
View Full Code Here

     * A method to wrap the default renderer of the JTableHeader if it does not
     * appear to be wrapped already. This is particularly useful when the UI
     * delegate of the table header changes.
     */
    private void wrapDefaultTableHeaderRenderer() {
        final TableCellRenderer defaultRenderer = table.getTableHeader().getDefaultRenderer();
        final Class defaultRendererType = defaultRenderer == null ? null : defaultRenderer.getClass();

        // if the renderer does not appear to be wrapped, do it
        if (defaultRendererType != SortArrowHeaderRenderer.class && defaultRendererType != null) {
            // decorate the default table header renderer with sort arrows
            sortArrowHeaderRenderer = new SortArrowHeaderRenderer(defaultRenderer);
View Full Code Here

        undecorateUIDelegateMouseListener(table);

        // fetch information about the hierarchical column
        final int viewColumnIndex = table.convertColumnIndexToView(hierarchyColumnModelIndex);
        final TableColumn viewColumn = table.getColumnModel().getColumn(viewColumnIndex);
        final TableCellRenderer renderer = viewColumn.getCellRenderer();
        final TableCellEditor editor = viewColumn.getCellEditor();

        // if the TreeTableCellRenderer is still installed, reinstall the original TableCellRenderer
        if (renderer == treeTableCellRenderer)
            viewColumn.setCellRenderer(originalRenderer);
View Full Code Here

        EventTableModel<Color> tableModel = new EventTableModel<Color>(colors, greenBlueTableFormat);

        // prepare the table for sorting and rendering its header
        JTable table = new JTable(tableModel);
        TableComparatorChooser<Color> tableComparatorChooser = TableComparatorChooser.install(table, sortedColors, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
        TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();

        // sort by each column in sequence
        clickColumnHeader(table, 0);
        assertEquals(rbg, sortedColors);
        clickColumnHeader(table, 1);
        assertEquals(rgb, sortedColors);

        // make sure we can still paint the header cells
        headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 0);
        // make sure we can handle negative indexes
        final Component rendered = headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, -1, -1);
        // no sort icon expected
        if (rendered instanceof JLabel) {
            assertNull(((JLabel) rendered).getIcon());
        }

        // uninstall the table comparator chooser and make sure no ill effects are left behind
        tableComparatorChooser.dispose();
        headerRenderer = table.getTableHeader().getDefaultRenderer();

        // clicking column headers shouldn't change anything after the comparator
        // chooser is disposed
        clickColumnHeader(table, 0);
        assertEquals(rgb, sortedColors);
        clickColumnHeader(table, 1);
        assertEquals(rgb, sortedColors);

        // make sure we can still paint the header cells
        headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 0);
        headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 1);

        // now create a three column table
        TableFormat<Color> redGreenBlueTableFormat = GlazedLists.tableFormat(new String[] { "red", "green", "blue" }, new String[] { "Red", "Green", "Blue" });
        tableModel.setTableFormat(redGreenBlueTableFormat);

        // make sure we can paint all three header cells
        headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 0);
        headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 1);
        headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 2);

        // try out the new table for sorting
        TableComparatorChooser.install(table, sortedColors, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
        sortedColors.setComparator(null);
        assertEquals(rgb, sortedColors);
View Full Code Here

        final String[] columnLabels = {"Column 1"};
        final TableFormat<String> itemTableFormat = GlazedLists.tableFormat(propertyNames, columnLabels);
        final EventTableModel<String> model = new EventTableModel<String>(treeList, itemTableFormat);
        final JTable table = new JTable(model);
        final TableColumn hierarchyColumn = table.getColumnModel().getColumn(0);
        final TableCellRenderer originalRenderer = new DefaultTableCellRenderer();
        final TableCellEditor originalEditor = new DefaultCellEditor(new JComboBox());
        hierarchyColumn.setCellRenderer(originalRenderer);
        hierarchyColumn.setCellEditor(originalEditor);

        // extract some information from the JTable before installing TreeTableSupport
View Full Code Here

TOP

Related Classes of javax.swing.table.TableCellRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.