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


Java JTable.setTableHeader方法代码示例

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


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

示例1: installEditableHeader

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * This method installs the given renderer and editors to the header of the given table. The
 * previous header names will be discarded and replaced by the objects given as initivalValues.
 * These might be changed by the editor components. After this, they might be returned by
 * getHeaderValue.
 */
public static void installEditableHeader(JTable table, TableCellRenderer headerRenderer, TableCellEditor headerEditor,
		Object[] initialValues) {
	TableColumnModel columnModel = table.getColumnModel();
	table.setTableHeader(new EditableTableHeader(columnModel));

	for (int i = 0; i < table.getColumnCount(); i++) {
		EditableTableHeaderColumn col = (EditableTableHeaderColumn) table.getColumnModel().getColumn(i);
		col.setHeaderValue(initialValues[i]);
		col.setHeaderRenderer(headerRenderer);
		col.setHeaderEditor(headerEditor);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:19,代码来源:EditableHeaderJTable.java

示例2: UpdateUIRecursionTest

import javax.swing.JTable; //导入方法依赖的package包/类
public UpdateUIRecursionTest() {
    super("UpdateUIRecursionTest");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);

     String[] columnNames = {
            "First Name",
            "Last Name",
            "Sport",
            "# of Years",
            "Vegetarian"};

            Object[][] data = {
                {"Mary", "Campione",
                "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                "Pool", new Integer(10), new Boolean(false)}
            };

    JTableHeader tableHeader =  new JTableHeader();
    table = new JTable(data, columnNames);
    table.setTableHeader(tableHeader);
    tableHeader.setDefaultRenderer(this);

    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);

    setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:UpdateUIRecursionTest.java

示例3: AttrTable

import javax.swing.JTable; //导入方法依赖的package包/类
public AttrTable(Window parent) {
	super(new BorderLayout());
	this.parent = parent;

	titleEnabled = true;
	title = new TitleLabel();
	title.setHorizontalAlignment(SwingConstants.CENTER);
	title.setVerticalAlignment(SwingConstants.CENTER);
	tableModel = new TableModelAdapter(parent, NULL_ATTR_MODEL);
	table = new JTable(tableModel);
	table.setDefaultEditor(Object.class, editor);
	table.setTableHeader(null);
	table.setRowHeight(20);

	Font baseFont = title.getFont();
	int titleSize = Math.round(baseFont.getSize() * 1.2f);
	Font titleFont = baseFont.deriveFont((float) titleSize).deriveFont(Font.BOLD);
	title.setFont(titleFont);
	Color bgColor = new Color(240, 240, 240);
	setBackground(bgColor);
	table.setBackground(bgColor);
	Object renderer = table.getDefaultRenderer(String.class);
	if (renderer instanceof JComponent) {
		((JComponent) renderer).setBackground(Color.WHITE);
	}

	JScrollPane tableScroll = new JScrollPane(table);

	this.add(title, BorderLayout.PAGE_START);
	this.add(tableScroll, BorderLayout.CENTER);
	LocaleManager.addLocaleListener(this);
	localeChanged();
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:34,代码来源:AttrTable.java

示例4: initComponents

import javax.swing.JTable; //导入方法依赖的package包/类
private void initComponents() {
    JTable impl = new JTable(new DefaultTableModel(new Object[] { "" }, 0)); // NOI18N
    TableColumnModel colMod = impl.getColumnModel();
    final TableColumn col = colMod.getColumn(0);
    impl.setFocusable(false);
    header = new Header(colMod);
    impl.setTableHeader(header);
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);

    final TableCellRenderer renderer = header.getDefaultRenderer();
    header.setDefaultRenderer(new TableCellRenderer() {
        public Component getTableCellRendererComponent(
                JTable table, Object value, boolean isSelected, boolean hasFocus,
                int row, int column) {

            Component component = renderer.getTableCellRendererComponent(
                    table, getRendererValue(), isSelected(),
                    isSelected(), row, processMouseEvents() ? 0 : 1);

            setupRenderer(component);

            col.setWidth(header.getWidth());
            return component;
        }
    });

    JScrollPane scroll = new JScrollPane(impl, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                                               JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) {
        public Dimension getPreferredSize() { return header.getPreferredSize(); }
        public void reshape(int x, int y, int width, int height) {
            header.setPreferredSize(new Dimension(width, height));
            super.reshape(x, y, width, height);
        }
    };
    scroll.setBorder(BorderFactory.createEmptyBorder());
    scroll.setViewportBorder(BorderFactory.createEmptyBorder());

    setLayout(new OverlayLayout(this));
    add(scroll);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:HeaderPanel.java


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