當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。