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


Java JTable.getTableHeader方法代码示例

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


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

示例1: FitTableColumns

import javax.swing.JTable; //导入方法依赖的package包/类
public static void FitTableColumns(JTable myTable){
	  JTableHeader header = myTable.getTableHeader();
	     int rowCount = myTable.getRowCount();
	     Enumeration columns = myTable.getColumnModel().getColumns();
	     while(columns.hasMoreElements()){
	         TableColumn column = (TableColumn)columns.nextElement();
	         int col = header.getColumnModel().getColumnIndex(column.getIdentifier());
	         int width = (int)myTable.getTableHeader().getDefaultRenderer()
	                 .getTableCellRendererComponent(myTable, column.getIdentifier()
	                         , false, false, -1, col).getPreferredSize().getWidth();
	         for(int row = 0; row<rowCount; row++){
	             int preferedWidth = (int)myTable.getCellRenderer(row, col).getTableCellRendererComponent(myTable,
	               myTable.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
	             width = Math.max(width, preferedWidth);
	         }
	         header.setResizingColumn(column); // ���к���Ҫ
	         column.setWidth(width+myTable.getIntercellSpacing().width);
	     }
}
 
开发者ID:sivanWu0222,项目名称:SimpleERP,代码行数:20,代码来源:QueryPortBelongs.java

示例2: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
public Component getTableCellRendererComponent (JTable table, Object value,
                                                boolean isSelected, boolean hasFocus,int row, int column) {
    
    if (table != null) {
        JTableHeader header = table.getTableHeader();
        if (header != null) {
            setForeground(header.getForeground());
            setBackground(header.getBackground());
            setFont(header.getFont());
        }
    }
    
    AttlistTableModel tm = (AttlistTableModel)table.getModel();
    if (column == tm.SortedColumn)
        setIcon(tm.ascending ? new javax.swing.ImageIcon(getClass().getResource("down.gif")): // NOI18N
                new javax.swing.ImageIcon(getClass().getResource("up.gif"))); // NOI18N
    else setIcon(new javax.swing.ImageIcon(getClass().getResource("no.gif"))); // NOI18N
    
    setText((value == null) ? "" : value.toString()); // NOI18N
    return this;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TreeElementAttributeListCustomizer.java

示例3: addMouseListenerToHeaderInTable

import javax.swing.JTable; //导入方法依赖的package包/类
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TableSorter.java

示例4: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (table != null) {
        JTableHeader header = table.getTableHeader();

        if (header != null) {
            setForeground(header.getForeground());
            setBackground(header.getBackground());
            setFont(header.getFont());
        }
    }

    if (isSelected) {
        setFont(getFont().deriveFont(Font.BOLD));
    }

    setText((value == null) ? "" : value.toString());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));

    return this;
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:23,代码来源:Table.java

示例5: addMouseListenerToHeaderInTable

import javax.swing.JTable; //导入方法依赖的package包/类
public void addMouseListenerToHeaderInTable(JTable table) { 
    final TableSorter sorter = this; 
    final JTable tableView = table; 
    tableView.setColumnSelectionAllowed(false); 
    MouseAdapter listMouseListener = new MouseAdapter() {
        boolean ascending = false;
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX()); 
            int column = tableView.convertColumnIndexToModel(viewColumn); 
            if (e.getClickCount() == 1 && column != -1) {
                //System.out.println("Sorting ..."); 
                //int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; 
                //boolean ascending = (shiftPressed == 0);
                if (column == sortBy)                    
                    ascending = !ascending;
                else
                    ascending = true; 
                sorter.sortByColumn(column, ascending);   
                tableView.getTableHeader().updateUI();                  
            }
        }
    };
    JTableHeader th = tableView.getTableHeader(); 
    th.addMouseListener(listMouseListener); 
}
 
开发者ID:ser316asu,项目名称:Wilmersdorf_SER316,代码行数:27,代码来源:TableSorter.java

示例6: erzeugeKundenTable

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Erzeugt die Tabelle für die Anzeige der Kunden.
 */
private void erzeugeKundenTable()
{
    JScrollPane kundenAuflisterScrollPane = new JScrollPane();
    kundenAuflisterScrollPane.setBorder(BorderFactory.createTitledBorder(
            null, "Kunden", TitledBorder.LEADING,
            TitledBorder.DEFAULT_POSITION, UIConstants.HEADER_FONT));
    kundenAuflisterScrollPane.setBackground(UIConstants.BACKGROUND_COLOR);
    kundenAuflisterScrollPane.getVerticalScrollBar()
        .setBackground(UIConstants.BACKGROUND_COLOR);
    kundenAuflisterScrollPane.getHorizontalScrollBar()
        .setBackground(UIConstants.BACKGROUND_COLOR);

    _kundenTableModel = new KundenTableModel();
    _kundenTable = new JTable();
    kundenAuflisterScrollPane.setViewportView(_kundenTable);
    _kundenTable.setModel(_kundenTableModel);
    _kundenTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JTableHeader tableHeader = _kundenTable.getTableHeader();
    tableHeader.setFont(UIConstants.HEADER_FONT);
    tableHeader.setReorderingAllowed(false);
    tableHeader.setResizingAllowed(false);
    _kundenTable.setFont(UIConstants.TEXT_FONT);

    _hauptPanel.add(kundenAuflisterScrollPane, BorderLayout.CENTER);
}
 
开发者ID:polemonium,项目名称:SE2Project,代码行数:29,代码来源:KundenauflisterUI.java

示例7: erzeugeMedienTable

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Erzeugt die Tabelle für die Anzeige der Medien.
 */
private void erzeugeMedienTable()
{
    JScrollPane medienAuflisterScrollPane = new JScrollPane();
    medienAuflisterScrollPane.setBorder(BorderFactory.createTitledBorder(
            null, "Medien", TitledBorder.LEADING,
            TitledBorder.DEFAULT_POSITION, UIConstants.HEADER_FONT));
    medienAuflisterScrollPane.setBackground(UIConstants.BACKGROUND_COLOR);
    medienAuflisterScrollPane.getVerticalScrollBar()
        .setBackground(UIConstants.BACKGROUND_COLOR);
    medienAuflisterScrollPane.getHorizontalScrollBar()
        .setBackground(UIConstants.BACKGROUND_COLOR);

    _medienTableModel = new VormerkMedienTableModel();
    _medienTable = new JTable();
    medienAuflisterScrollPane.setViewportView(_medienTable);
    _medienTable.setModel(_medienTableModel);
    JTableHeader tableHeader = _medienTable.getTableHeader();
    tableHeader.setFont(UIConstants.HEADER_FONT);
    tableHeader.setReorderingAllowed(false);
    tableHeader.setResizingAllowed(false);
    _medienTable.setFont(UIConstants.TEXT_FONT);

    _hauptPanel.add(medienAuflisterScrollPane, BorderLayout.CENTER);
}
 
开发者ID:polemonium,项目名称:SE2Project,代码行数:28,代码来源:VormerkMedienauflisterUI.java

示例8: installFor

import javax.swing.JTable; //导入方法依赖的package包/类
public static void installFor(JTable table, JPopupMenu popupMenu, int column) {
    removeOldHeaderMouseListener(table);
    TableModel model = table.getModel();
    model.addTableModelListener(new HeaderCheckBoxHandler(table));
    table.getTableHeader().addMouseListener(new HeaderMouseListener(popupMenu, column));
    TableCellRenderer r = new HeaderRenderer(table.getTableHeader(), popupMenu, column);
    table.getColumnModel().getColumn(column).setHeaderRenderer(r);
    TableCellRenderer leftAlign = new LeftAlignHeaderRenderer();
    for (int i = 0; i < table.getColumnCount(); i++) {
        if (i != column) {
            table.getColumnModel().getColumn(i).setHeaderRenderer(leftAlign);
        }
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:15,代码来源:TableCheckBoxColumn.java

示例9: StatisticsDialog

import javax.swing.JTable; //导入方法依赖的package包/类
private StatisticsDialog(JFrame parent, String circuitName, StatisticsTableModel model) {
	super(parent, true);
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	setTitle(Strings.get("statsDialogTitle", circuitName));

	JTable table = new StatisticsTable();
	TableSorter mySorter = new TableSorter(model, table.getTableHeader());
	Comparator<String> comp = new CompareString("", Strings.get("statsTotalWithout"),
			Strings.get("statsTotalWith"));
	mySorter.setColumnComparator(String.class, comp);
	table.setModel(mySorter);
	JScrollPane tablePane = new JScrollPane(table);

	JButton button = new JButton(Strings.get("statsCloseButton"));
	button.addActionListener(this);
	JPanel buttonPanel = new JPanel();
	buttonPanel.add(button);

	Container contents = this.getContentPane();
	contents.setLayout(new BorderLayout());
	contents.add(tablePane, BorderLayout.CENTER);
	contents.add(buttonPanel, BorderLayout.PAGE_END);
	this.pack();
	this.setLocationRelativeTo(null);
	Dimension pref = contents.getPreferredSize();
	if (pref.width > 750 || pref.height > 550) {
		if (pref.width > 750)
			pref.width = 750;
		if (pref.height > 550)
			pref.height = 550;
		this.setSize(pref);
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:34,代码来源:StatisticsDialog.java

示例10: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
		int row, int column) {
	if (table != null) {
		JTableHeader header = table.getTableHeader();
		if (header != null) {
			setFont(header.getFont());
		}
	}

	this.rollOver = column == TableHeaderUI.this.highlightedColumn;
	if (header != null) {
		curCol = column;
		this.isLeftmost = column == 0;
		this.isRightmost = column == header.getColumnModel().getColumnCount() - 1;
	}

	if (header != null && header.getDraggedColumn() != null) {
		this.isPressed = viewIndexForColumn(header.getDraggedColumn()) == column
				|| column == TableHeaderUI.this.pressedColumn;
	} else {
		this.isPressed = false;
	}
	setText(value == null ? "" : value.toString());
	setHorizontalAlignment(SwingConstants.LEFT);
	setHorizontalTextPosition(SwingConstants.LEADING);
	setBorder(HEADER_BORDER);
	return this;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:30,代码来源:TableHeaderUI.java

示例11: RowHeaderRenderer

import javax.swing.JTable; //导入方法依赖的package包/类
public RowHeaderRenderer(JTable table) {
	JTableHeader header = table.getTableHeader();
	setOpaque(true);
	setBorder(UIManager.getBorder("TableHeader.cellBorder"));
	setHorizontalAlignment(CENTER);
	setForeground(header.getForeground());
	setBackground(header.getBackground());
	setFont(header.getFont());
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:10,代码来源:RowHeaderRenderer.java

示例12: getColumnName

import javax.swing.JTable; //导入方法依赖的package包/类
public String getColumnName(int c) {
    JTable table = (JTable) component;
    JTableHeader tableHeader = table.getTableHeader();
    String columnName;
    if (tableHeader != null) {
        columnName = tableHeader.getColumnModel().getColumn(c).getHeaderValue().toString();
    } else {
        columnName = table.getColumnName(c);
    }
    return columnName;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:12,代码来源:JavaElementPropertyAccessor.java

示例13: fitTableColumns

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

        JTableHeader header = myTable.getTableHeader();
        int rowCount = myTable.getRowCount();
        Enumeration columns = myTable.getColumnModel().getColumns();
        while (columns.hasMoreElements()) {
            TableColumn column = (TableColumn) columns.nextElement();
            int col = header.getColumnModel().getColumnIndex(
                    column.getIdentifier());
            int width = (int) myTable
                    .getTableHeader()
                    .getDefaultRenderer()
                    .getTableCellRendererComponent(myTable,
                            column.getIdentifier(), false, false, -1, col)
                    .getPreferredSize().getWidth();
            for (int row = 0; row < rowCount; row++) {
                int preferedWidth = (int) myTable
                        .getCellRenderer(row, col)
                        .getTableCellRendererComponent(myTable,
                                myTable.getValueAt(row, col), false, false,
                                row, col).getPreferredSize().getWidth();
                width = Math.max(width, preferedWidth);
            }
            header.setResizingColumn(column); // 此行很重要
            column.setWidth(width + myTable.getIntercellSpacing().width + 4);// 使表格看起来不是那么拥挤,起到间隔作用
        }
    }
 
开发者ID:Harlber,项目名称:Method_Trace_Tool,代码行数:28,代码来源:Utils.java

示例14: ColumnGroup

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Standard ColumnGroup constructor.
 *
 * @param renderer a TableCellRenderer for the group.
 * @param text     Name of the ColumnGroup which will be displayed
 *                 when the ColumnGroup is renderered.
 */
public ColumnGroup(TableCellRenderer renderer, String text) {
    if (renderer == null) {
        this.renderer = new DefaultTableCellRenderer() {
            /**
             *
             */
            private static final long serialVersionUID = -5535756297988645866L;

            public Component getTableCellRendererComponent(JTable table, Object value,
                                                           boolean isSelected, boolean hasFocus, int row, int column) {
                JTableHeader header = table.getTableHeader();
                if (header != null) {
                    setForeground(header.getForeground());
                    setBackground(header.getBackground());
                    setFont(header.getFont());
                }
                setHorizontalAlignment(JLabel.CENTER);
                setText((value == null) ? "" : value.toString());
                setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                return this;
            }
        };
    } else {
        this.renderer = renderer;
    }
    this.text = text;
    v = new Vector<Object>();
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:36,代码来源:ColumnGroup.java

示例15: RowHeaderRenderer

import javax.swing.JTable; //导入方法依赖的package包/类
RowHeaderRenderer(final JTable table) {
    this.table = table;
    normalBorder = UIManager.getBorder("TableHeader.cellBorder");
    selectedBorder = BorderFactory.createRaisedBevelBorder();
    final JTableHeader header = table.getTableHeader();
    normalFont = header.getFont();
    selectedFont = normalFont.deriveFont(normalFont.getStyle() | Font.BOLD);
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setOpaque(true);
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:12,代码来源:RowHeaderRenderer.java


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