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


Java JTable.setSize方法代碼示例

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


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

示例1: show

import javax.swing.JTable; //導入方法依賴的package包/類
public void show(int dif) {

			ArrayList<record> rec = new ArrayList<record>();

			String content = FileHelper.readFromFile("ranking.ini");
			if (content != null ) {
				if(!content.equals("")) {
					String[] sp = content.split(",");
					for (int i = 0; i < sp.length; i = i + 3) {
						if (dif == Integer.parseInt(sp[i])) {
							rec.add(new record(sp[i + 2], Integer.parseInt(sp[i + 1])));
						}
					}
				}
				Collections.sort(rec);
				rank = new Object[rec.size()][COL];
				for (int i = 0; i < rec.size(); i++) {
					record temp = rec.get(i);
					rank[i][0] = i + 1;
					rank[i][2] = temp.date;
					rank[i][1] = temp.score;
				}

				table = new JTable(rank, title);
				centerPanel.removeAll();
				centerPanel.setLayout(new BorderLayout());
				centerPanel.add(new JScrollPane(table), BorderLayout.CENTER);
				DefaultTableCellRenderer r = new DefaultTableCellRenderer();
				r.setHorizontalAlignment(JLabel.CENTER);
				table.setDefaultRenderer(Object.class, r);
				table.setRowHeight(20);
				table.setFont(new Font("微軟雅黑", 0, 14));
				table.setGridColor(Color.BLUE);
				table.setSize(centerPanel.getWidth(), centerPanel.getHeight());
				table.setRowSelectionAllowed(false);

			}
			setVisible(true);
		}
 
開發者ID:zhangjikai,項目名稱:LinkGame,代碼行數:40,代碼來源:Ranking.java

示例2: checkTableGridLines

import javax.swing.JTable; //導入方法依賴的package包/類
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:DrawGridLinesTest.java

示例3: resize

import javax.swing.JTable; //導入方法依賴的package包/類
/**
 * Forces the table to resize given column.
 */
private void resize(int newWidth, JTable table) {
    int oldWidth = getWidth();
    JTableHeader header = table.getTableHeader();
    if (header == null) {
        return;
    }
    header.setResizingColumn(this);
    final int oldMin = getMinWidth();
    final int oldMax = getMaxWidth();
    setMinWidth(newWidth);
    setMaxWidth(newWidth);
    setWidth(newWidth);
    // The trick is to restore the original values
    // after the table has be layouted. During layout this column
    // has fixed width (by setting min==max==preffered)
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            setMinWidth(oldMin);
            setMaxWidth(oldMax);
        }
    });
    Container container;
    if ((header.getParent() == null) ||
            ((container = header.getParent().getParent()) == null) ||
            !(container instanceof JScrollPane)) {
        header.setResizingColumn(null);
        return;
    }
    
    if (!container.getComponentOrientation().isLeftToRight() &&
            ! header.getComponentOrientation().isLeftToRight()) {
        if (table != null) {
            JViewport viewport = ((JScrollPane)container).getViewport();
            int viewportWidth = viewport.getWidth();
            int diff = newWidth - oldWidth;
            int newHeaderWidth = table.getWidth() + diff;
            
            /* Resize a table */
            Dimension tableSize = table.getSize();
            tableSize.width += diff;
            table.setSize(tableSize);
            
            /* If this table is in AUTO_RESIZE_OFF mode and
             * has a horizontal scrollbar, we need to update
             * a view's position.
             */
            if ((newHeaderWidth >= viewportWidth) &&
                    (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                Point p = viewport.getViewPosition();
                p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                viewport.setViewPosition(p);
            }
        }
    }
    header.setResizingColumn(null);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:61,代碼來源:ETableColumn.java


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