當前位置: 首頁>>代碼示例>>Java>>正文


Java JXTable.getColumnCount方法代碼示例

本文整理匯總了Java中org.jdesktop.swingx.JXTable.getColumnCount方法的典型用法代碼示例。如果您正苦於以下問題:Java JXTable.getColumnCount方法的具體用法?Java JXTable.getColumnCount怎麽用?Java JXTable.getColumnCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jdesktop.swingx.JXTable的用法示例。


在下文中一共展示了JXTable.getColumnCount方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPreferredScrollableViewportWidth

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/**
 * Calculates and returns the preferred scrollable viewport 
 * width of the given table. Subclasses are free to override
 * and implement a custom strategy.<p>
 * 
 * This implementation sums the pref widths of the first
 * visibleColumnCount contained visible tableColumns. If
 * the table contains less columns, the standard preferred
 * width per column is added to the result. 
 * 
 * @param table the table containing the columns
 */
public int getPreferredScrollableViewportWidth(JXTable table) {
    int w = 0;
    int count;
    if (table.getVisibleColumnCount() < 0) {
        count = table.getColumnCount();
    } else {
        count = Math.min(table.getColumnCount(), table.getVisibleColumnCount());
    }
    for (int i = 0; i < count; i++) {
        // sum up column's pref size, until maximal the
        // visibleColumnCount
        w += table.getColumn(i).getPreferredWidth();
    }
    if (count < table.getVisibleColumnCount()) {
        w += (table.getVisibleColumnCount() - count) * 75;
    }
    return w;
    
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:32,代碼來源:ColumnFactory.java

示例2: testTableMovedColumn

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/** 
 * test that the search predicate's highlight column index is in 
 * model coordinates
 *
 */
@Test
public void testTableMovedColumn() {
    JXTable table = new JXTable(new TestTableModel());
    table.putClientProperty(AbstractSearchable.MATCH_HIGHLIGHTER, Boolean.TRUE);
    
    // move first column to end
    int firstColumn = table.getColumnCount() - 1;
    table.getColumnModel().moveColumn(0, firstColumn);
    int row = 39;
    String firstSearchText = table.getValueAt(row, firstColumn).toString();
    PatternModel model = new PatternModel();
    model.setRawText(firstSearchText);
    // initialize searchable to "found state"
    table.getSearchable().search(model.getPattern(), -1);
    // column index in view coordinates
    int foundColumn = ((AbstractSearchable) table.getSearchable()).lastSearchResult.foundColumn;
    assertEquals("column must be updated", firstColumn, foundColumn);
    AbstractHighlighter hl = ((AbstractSearchable) table.getSearchable()).getMatchHighlighter();
    assertTrue("searchPredicate", hl.getHighlightPredicate() instanceof SearchPredicate);
    SearchPredicate predicate = (SearchPredicate) hl.getHighlightPredicate();
    assertEquals(table.convertColumnIndexToModel(firstColumn), predicate.getHighlightColumn());
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:28,代碼來源:SearchableTest.java

示例3: testTableFoundPreviousColumnInSameRow

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/**
 * test if match in same row but different column is found in backwards
 * search.
 *
 */
@Test
public void testTableFoundPreviousColumnInSameRow() {
    JXTable table = new JXTable(new TestTableModel());
    int lastColumn = table.getColumnCount() -1;
    int row = 90;
    String firstSearchText = table.getValueAt(row, lastColumn).toString();
    // need a pattern for backwards search
    PatternModel model = new PatternModel();
    model.setRawText(firstSearchText);
    int foundIndex = table.getSearchable().search(model.getPattern(), -1, true);
    assertEquals("last line found", row, foundIndex);
    String secondSearchText = table.getValueAt(row, lastColumn - 1).toString();
    model.setRawText(secondSearchText);
    int secondFoundIndex = table.getSearchable().search(model.getPattern(), foundIndex, true);
    assertEquals("must find match in same row", foundIndex, secondFoundIndex);
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:22,代碼來源:FindTest.java

示例4: testColumnControlReleaseAction

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
@Test
public void testColumnControlReleaseAction() {
    final JXTable table = new JXTable(sortableTableModel);
    final TableColumnExt priorityColumn = table.getColumnExt("First Name");
    int listenerCount = priorityColumn.getPropertyChangeListeners().length;
    table.setColumnControlVisible(true);
    // JW: the columnControlButton is created lazily, so we
    // have to access to test if listeners are registered.
    table.getColumnControl();
    assertEquals("numbers of listeners must be increased", listenerCount + 1, 
            priorityColumn.getPropertyChangeListeners().length);
    int totalColumnCount = table.getColumnCount();
    table.removeColumn(priorityColumn);
    assertEquals("number of columns reduced", totalColumnCount - 1, table.getColumnCount());
    assertEquals("all listeners must be removed", 0, 
            priorityColumn.getPropertyChangeListeners().length);
 }
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:18,代碼來源:ColumnControlButtonTest.java

示例5: updateRowHeight

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/**
 * Sets per-row rowHeight based on the rendering component's preferred height.
 * 
 * @param table
 */
private void updateRowHeight(final JXTable table) {
    for (int row = 0; row < table.getRowCount(); row++) {
        int rowHeight = 0;
        for (int column = 0; column < table.getColumnCount(); column++) {
            Component comp = table.prepareRenderer(table
                    .getCellRenderer(row, column), row, column);
            rowHeight = Math.max(rowHeight,
                    comp.getPreferredSize().height);
        }
        table.setRowHeight(row, rowHeight); 
    }
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:18,代碼來源:RendererVisualCheck.java

示例6: testTableFoundNextColumnInPreviousRow

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/**
 * test if search loops all columns of previous row (backwards search).
 * 
 * Hmm... not testable? 
 * Needed to widen access for lastFoundColumn.
 */
@Test
public void testTableFoundNextColumnInPreviousRow() {
    JXTable table = new JXTable(new TestTableModel());
    int lastColumn = table.getColumnCount() -1;
    int row = 39;
    int firstColumn = lastColumn - 1;
    String firstSearchText = table.getValueAt(row, firstColumn).toString();
    // need a pattern for backwards search
    PatternModel model = new PatternModel();
    model.setRawText(firstSearchText);
    int foundIndex = table.getSearchable().search(model.getPattern(), -1, true);
    assertEquals("last line found", row, foundIndex);
    int foundColumn = ((TableSearchable) table.getSearchable()).lastSearchResult.foundColumn;
    assertEquals("column must be updated", firstColumn, foundColumn);
    // the last char(s) of all values is the row index
    // here we are searching for an entry in the next row relative to
    // the previous search and expect the match in the first column (index = 0);
    int previousRow = row -1;
    String secondSearchText = String.valueOf(previousRow);
    model.setRawText(secondSearchText);
    int secondFoundIndex = table.getSearchable().search(model.getPattern(), previousRow, true);
    // sanity assert
    assertEquals("must find match in same row", previousRow, secondFoundIndex);
    assertEquals("column must be updated", lastColumn, ((TableSearchable) table.getSearchable()).lastSearchResult.foundColumn);
    
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:33,代碼來源:FindTest.java

示例7: interactiveNumberEditor

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/**
 * Issue #393-swingx: localized NumberEditor.
 * 
 * Column type is Number, editors as noted in header text 
 * 
 * 
 */
public void interactiveNumberEditor() {
    final int doubleColumns = 3;
    final int integerColumns = 6;
    DefaultTableModel model = new DefaultTableModel(new String[] {
            "Double-core", "Double-extstrict", "Double-extnonstrict", 
            "Integer-core", "Integer-extstrict", "Integer-extnonstrict",
    "Object" }, 10) {
        
        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return Number.class;
        }
        
    };
    final JXTable table = new JXTable(model);
    table.setSurrendersFocusOnKeystroke(true);
    for (int i = 0; i < table.getColumnCount(); i++) {
        if (i < doubleColumns) {
            table.setValueAt(Double.MAX_VALUE-1, 0, i);
        } else {
            table.setValueAt(Integer.MAX_VALUE-1, 0, i);
        }
        
    }
    NumberEditor numberEditor = new NumberEditor();
    table.getColumn(0).setCellEditor(numberEditor);
    table.getColumn(doubleColumns).setCellEditor(numberEditor);
    NumberEditorExt nonStrictEditor = new NumberEditorExt(false);
    table.getColumn(doubleColumns -1).setCellEditor(nonStrictEditor);
    table.getColumn(integerColumns -1).setCellEditor(nonStrictEditor);
    JXFrame frame = showWithScrollingInFrame(table, "Extended NumberEditors: Number.class");
    addStatusMessage(frame, "number-class: has no constructor with string, core/nonstrict can't handle");
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:41,代碼來源:NumberEditorExtTest.java

示例8: interactiveFloatingPointEditor

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/**
 * Issue #393-swingx: localized NumberEditor.
 * 
 * Column type is Number, editors as noted in header text 
 * 
 * 
 */
public void interactiveFloatingPointEditor() {
    final int doubleColumns = 3;
    final int integerColumns = 6;
    DefaultTableModel model = new DefaultTableModel(new String[] {
            "Double-core", "Double-extstrict", "Double-extnonstrict", 
            "Integer-core", "Integer-extstrict", "Integer-extnonstrict",
            "Object" }, 10) {

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex < doubleColumns) {
                return Double.class;
            }
            if (columnIndex < integerColumns) {
                return Integer.class;

            }
            return Object.class;
        }

    };
    final JXTable table = new JXTable(model);
    table.setSurrendersFocusOnKeystroke(true);
    for (int i = 0; i < table.getColumnCount(); i++) {
        if (i < doubleColumns) {
            table.setValueAt(Double.MAX_VALUE, 0, i);
        } else {
            table.setValueAt(Integer.MAX_VALUE, 0, i);
        }

    }
    NumberEditor numberEditor = new NumberEditor();
    table.getColumn(0).setCellEditor(numberEditor);
    table.getColumn(doubleColumns).setCellEditor(numberEditor);
    NumberEditorExt nonStrictEditor = new NumberEditorExt(false);
    table.getColumn(doubleColumns -1).setCellEditor(nonStrictEditor);
    table.getColumn(integerColumns -1).setCellEditor(nonStrictEditor);
    showWithScrollingInFrame(table, "Extended NumberEditors: concrete classes Double/Integer");
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:47,代碼來源:NumberEditorExtTest.java

示例9: testColumnControlInvisibleColumns

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/** 
    * Issue #192: initially invisibility columns are hidden
    * but marked as visible in control.
    *
    * Issue #38 (swingx): initially invisble columns don't show up
    * in the column control list.
    * 
    * 
    */
    @Test
   public void testColumnControlInvisibleColumns() {
       final JXTable table = new JXTable(sortableTableModel);
       // columns set to invisible before setting the columnControl
       // will not be inserted into the column control's list
//     table.getColumnExt("Last Name").setVisible(false);
       table.setColumnControlVisible(true);
       int totalColumnCount = table.getColumnCount();
       final TableColumnExt priorityColumn = table.getColumnExt("First Name");
       priorityColumn.setVisible(false);
       ColumnControlButton columnControl = (ColumnControlButton) table.getColumnControl();
       assertNotNull("popup menu not null", columnControl.popup);
       int columnMenuItems = 0;
       Component[] items = ((DefaultColumnControlPopup) columnControl.getColumnControlPopup()).getPopupMenu().getComponents();
       for (int i = 0; i < items.length; i++) {
           if (!(items[i] instanceof JMenuItem)) {
               break;
           }
           columnMenuItems++;
       }
       // wrong assumption - has separator and actions!
       assertEquals("menu items must be equal to columns", totalColumnCount, 
               columnMenuItems);
       JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) ((DefaultColumnControlPopup) columnControl.getColumnControlPopup()).getPopupMenu()
           .getComponent(0);
       // sanit assert
       assertEquals(priorityColumn.getHeaderValue(), menuItem.getText());
       assertEquals("selection of menu must be equal to column visibility", 
               priorityColumn.isVisible(), menuItem.isSelected());
   }
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:40,代碼來源:ColumnControlButtonTest.java

示例10: testPatternPredicateAllColumns

import org.jdesktop.swingx.JXTable; //導入方法依賴的package包/類
/**
 * Issue #1317-swingx: PatternPredicate causes exception with testColumn -1 (ALL)
 * 
 */
@Test
public void testPatternPredicateAllColumns() {
    JXTable table = new JXTable(new AncientSwingTeam());
    PatternPredicate predicate = new PatternPredicate(".*e.*");
    table.addHighlighter(new ColorHighlighter(predicate, Color.BLUE, null));
    for (int i = 0; i < table.getRowCount(); i++) {
        for (int j = 0; j < table.getColumnCount(); j++) {
            TableCellRenderer renderer = table.getCellRenderer(i, j);
            table.prepareRenderer(renderer, i, j);
        }
    }
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:17,代碼來源:HighlightPredicateTest.java


注:本文中的org.jdesktop.swingx.JXTable.getColumnCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。