当前位置: 首页>>代码示例>>Java>>正文


Java JTable.getCellRenderer方法代码示例

本文整理汇总了Java中javax.swing.JTable.getCellRenderer方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getCellRenderer方法的具体用法?Java JTable.getCellRenderer怎么用?Java JTable.getCellRenderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTable的用法示例。


在下文中一共展示了JTable.getCellRenderer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resizeColumnWidth

import javax.swing.JTable; //导入方法依赖的package包/类
public void resizeColumnWidth(JTable table) {
    final TableColumnModel columnModel = table.getColumnModel();
    for (int column = 0; column < table.getColumnCount(); column++) {
        int width = 50; // Min width
        for (int row = 0; row < table.getRowCount(); row++) {
            TableCellRenderer renderer = table.getCellRenderer(row, column);
            Component comp = table.prepareRenderer(renderer, row, column);
            width = Math.max(comp.getPreferredSize().width, width);
        }
        columnModel.getColumn(column).setPreferredWidth(width);
        columnModel.getColumn(column).setMinWidth(minColumnWidths[column]);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:CoverageReportTopComponent.java

示例2: autoSizeTableColumns

import javax.swing.JTable; //导入方法依赖的package包/类
public static void autoSizeTableColumns(JTable table) {

        TableModel  model        = table.getModel();
        TableColumn column       = null;
        Component   comp         = null;
        int         headerWidth  = 0;
        int         maxCellWidth = Integer.MIN_VALUE;
        int         cellWidth    = 0;
        TableCellRenderer headerRenderer =
            table.getTableHeader().getDefaultRenderer();

        for (int i = 0; i < table.getColumnCount(); i++) {
            column = table.getColumnModel().getColumn(i);
            comp = headerRenderer.getTableCellRendererComponent(table,
                    column.getHeaderValue(), false, false, 0, 0);
            headerWidth  = comp.getPreferredSize().width + 10;
            maxCellWidth = Integer.MIN_VALUE;

            for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) {
                TableCellRenderer r = table.getCellRenderer(j, i);

                comp = r.getTableCellRendererComponent(table,
                                                       model.getValueAt(j, i),
                                                       false, false, j, i);
                cellWidth = comp.getPreferredSize().width;

                if (cellWidth >= maxCellWidth) {
                    maxCellWidth = cellWidth;
                }
            }

            column.setPreferredWidth(Math.max(headerWidth, maxCellWidth)
                                     + 10);
        }
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:36,代码来源:GridSwing.java

示例3: packColumn

import javax.swing.JTable; //导入方法依赖的package包/类
private static void packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.
            getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width;            // Obtém a largura do cabeçalho da coluna
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp = renderer.getTableCellRendererComponent(
            table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;            // Obtém a largura maxima da coluna de dados
    for (int r = 0; r < table.getRowCount(); r++) {
        renderer = table.getCellRenderer(r, vColIndex);
        comp = renderer.getTableCellRendererComponent(
                table, table.getValueAt(r, vColIndex), false, false, r,
                vColIndex);
        width = Math.max(width, comp.getPreferredSize().width);
    }
    width += 2 * margin;            // Configura a largura
    col.setPreferredWidth(width);
}
 
开发者ID:karlos7,项目名称:ViolenciaContraMulher,代码行数:23,代码来源:FormataTamanhoColunasJTable.java

示例4: buildTablePanel

import javax.swing.JTable; //导入方法依赖的package包/类
private JScrollPane buildTablePanel() {
      table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
      TableColumn nameColumn = new TableColumn(0);
      TableColumn addressColumn = new TableColumn(1);
      table.addColumn(nameColumn);
      table.addColumn(addressColumn);
      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
      table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
      table.addMouseListener(new AddressMouseListener());
      
      // TODO: isolate in utility
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(table, "123", false, false, 0, 0);
table.setRowHeight(new Double(comp.getPreferredSize().getHeight()).intValue() + 2);
      
      JScrollPane scrollPane = new JScrollPane(table);
      return scrollPane;
  }
 
开发者ID:ZencashOfficial,项目名称:zencash-swing-wallet-ui,代码行数:19,代码来源:AddressBookPanel.java

示例5: testRenderers

import javax.swing.JTable; //导入方法依赖的package包/类
public void testRenderers() {
    setUpModel();
    JTable t = ot.treeTable.getTable();
    ot.revalidate();

    javax.swing.JFrame f = new javax.swing.JFrame();
    f.setLayout(new BorderLayout());
    f.add(ot, BorderLayout.CENTER);
    f.setSize(600, 500);
    f.setVisible(true);
    //while (f.isVisible()) {
        try {
            Thread.sleep(333);
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        }
    //}
    
    System.out.println("table rows = "+t.getRowCount());
    TableCellRenderer tcr = t.getCellRenderer(0, 0);
    Component c = tcr.getTableCellRendererComponent(t, null, true, true, 0, 0);
    //System.err.println("c = "+c);
    assertTrue("Renderer component = "+c, c instanceof RendererComponent);
    assertEquals("Renderer of 0:DN", ((RendererComponent) c).getText());

    tcr = t.getCellRenderer(0, 1);
    c = tcr.getTableCellRendererComponent(t, null, true, true, 0, 1);
    assertEquals("Renderer of 0:col1", ((RendererComponent) c).getText());

    tcr = t.getCellRenderer(0, 2);
    c = tcr.getTableCellRendererComponent(t, null, true, true, 0, 2);
    assertEquals("Renderer of 0:col2", ((RendererComponent) c).getText());

    tcr = t.getCellRenderer(1, 0);
    c = tcr.getTableCellRendererComponent(t, null, true, true, 1, 0);
    assertFalse("Renderer component = "+c, c instanceof RendererComponent);

    tcr = t.getCellRenderer(1, 1);
    c = tcr.getTableCellRendererComponent(t, null, true, true, 1, 1);
    assertFalse("Renderer component = "+c, c instanceof RendererComponent);

    tcr = t.getCellRenderer(2, 1);
    c = tcr.getTableCellRendererComponent(t, null, true, true, 2, 1);
    assertEquals("Renderer of 2:col1", ((RendererComponent) c).getText());

    tcr = t.getCellRenderer(6, 0);
    c = tcr.getTableCellRendererComponent(t, null, true, true, 6, 0);
    assertEquals("Renderer of 6:DN", ((RendererComponent) c).getText());

    tcr = t.getCellRenderer(8, 2);
    c = tcr.getTableCellRendererComponent(t, null, true, true, 8, 2);
    assertEquals("Renderer of 8:col2", ((RendererComponent) c).getText());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:TableRendererTest.java


注:本文中的javax.swing.JTable.getCellRenderer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。