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


Java JTable.getColumnModel方法代码示例

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


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

示例1: deletecols

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * deletes all selected columns if it is not present in the <code>exp</code>
 * List
 *
 * @param table the table to DELETE columns
 * @param exp columns to avoid deleting
 * @see #deletecol(javax.swing.JTable, int)
 */
static void deletecols(JTable table, int[] exp) {
    Integer[] selcols;
    try {
        TableColumnModel tcm = table.getColumnModel();
        selcols = ArrayUtils.toObject(table.getSelectedColumns());
        Arrays.sort(selcols, Collections.reverseOrder());
        List<Integer> explist = Ints.asList(exp);
        for (int i : selcols) {
            if (!explist.contains(i)) {
                tcm.removeColumn(tcm.getColumn(i));
            }
        }

    } catch (Exception e) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, e);
    }

}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:27,代码来源:JtableUtils.java

示例2: 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,项目名称:SER316-Aachen,代码行数:27,代码来源:TableSorter.java

示例3: 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

示例4: 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TableSorter.java

示例5: mouseMoved

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void mouseMoved(MouseEvent evt) {
	TableColumn col = null;
	JTableHeader header = (JTableHeader) evt.getSource();
	JTable table = header.getTable();
	TableColumnModel colModel = table.getColumnModel();
	int vColIndex = colModel.getColumnIndexAtX(evt.getX());

	// Return if not clicked on any column header
	if (vColIndex >= 0) {
		col = colModel.getColumn(vColIndex);
	}

	if (col != curCol) {
		header.setToolTipText(tips.get(col));
		curCol = col;
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:19,代码来源:ColumnHeaderToolTips.java

示例6: mouseClicked

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    JTableHeader header = (JTableHeader) e.getSource();
    JTable table = header.getTable();
    TableColumnModel columnModel = table.getColumnModel();
    int vci = columnModel.getColumnIndexAtX(e.getX());
    int mci = table.convertColumnIndexToModel(vci);
    if (mci == targetColumnIndex) {
        if (SwingUtilities.isLeftMouseButton(e)) {
            TableColumn column = columnModel.getColumn(vci);
            Object v = column.getHeaderValue();
            boolean b = Status.DESELECTED.equals(v);
            TableModel m = table.getModel();
            for (int i = 0; i < m.getRowCount(); i++) {
                m.setValueAt(b, i, mci);
            }
            column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED);
        } else if (SwingUtilities.isRightMouseButton(e)) {
            if (popupMenu != null) {
                popupMenu.show(table, e.getX(), 0);
            }
        }
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:25,代码来源:TableCheckBoxColumn.java

示例7: CourseListPanel

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Create the panel.
 */
public CourseListPanel(String user,ProfessorFrame pf) throws Exception{
	setLayout(new BorderLayout(0, 0));
       TableCellRenderer buttonRenderer = new ButtonRenderer();
	dao = new ProfessorDAO();
	model=new tableModelTeach(dao.getAllCourses(user),user,pf);
	table = new JTable();
	table.setRowHeight(30);
	
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.setDefaultRenderer(JButton.class,buttonRenderer);
	table.addMouseListener(new JTableButtonMouseListener(table));
	table.setModel(model);
	JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	//resizeColumnWidth(table);
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	TableColumnModel tcm = table.getColumnModel();
	tcm.getColumn(0).setPreferredWidth(800);    
	tcm.getColumn(1).setPreferredWidth(200);    
	
	scrollPane.setBounds(10, 57, 1320, 450);
	add(scrollPane, BorderLayout.CENTER);
}
 
开发者ID:jtatia,项目名称:Course-Management-System,代码行数:26,代码来源:CourseListPanel.java

示例8: ResultsPane

import javax.swing.JTable; //导入方法依赖的package包/类
public ResultsPane(ResultsModel inModel)
{
	setLayout(new BorderLayout());

	mdl = inModel;

	ColorTimeRenderer large  = new ColorTimeRenderer(3);
	ColorTimeRenderer medium = new ColorTimeRenderer(2);
	//ColorTimeRenderer small  = new ColorTimeRenderer(1);
	DifferenceRenderer diff  = new DifferenceRenderer();

	tbl = new JTable(inModel) { public void tableChanged(TableModelEvent e) { super.tableChanged(e); scrollTable(); } };
	tbl.setDefaultRenderer(ColorTime.class, new ColorTimeRenderer(1));
	tbl.setRowHeight(140);
	tbl.setRowSelectionAllowed(false);
	//tbl.setIntercellSpacing(new Dimension(8, 8));

	TableColumnModel tcm = tbl.getColumnModel();
	columnStyle(tcm, 0, 50,  70,  200, medium);
	columnStyle(tcm, 1, 50,  70,  200, medium);
	columnStyle(tcm, 2, 80,  110, 280, large);

	columnStyle(tcm, 3, 180, 230, 700, diff);

	columnStyle(tcm, 4, 50,  70,  200, medium);
	columnStyle(tcm, 5, 50,  70,  200, medium);
	columnStyle(tcm, 6, 80,  110, 280, large);

	JScrollPane scroll = new JScrollPane(tbl, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	add(scroll);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:32,代码来源:ResultsPane.java

示例9: setTableRenderer

import javax.swing.JTable; //导入方法依赖的package包/类
public void setTableRenderer(JTable table) 
{
	TableColumnModel tColMod = table.getColumnModel();
	for (int i = 0; i < tColMod.getColumnCount(); i++) 
	{
		TableColumn tcol = tColMod.getColumn(i);
		tcol.setCellRenderer(this);			
	}
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:10,代码来源:BrainTableRenderer.java

示例10: TopTablePanel

import javax.swing.JTable; //导入方法依赖的package包/类
public TopTablePanel(final ElistTablePanel panel, JTable table) {
    super(table.getColumnModel());
    this.panel = panel;
    this.table = table;
    this.addMouseMotionListener(new MouseMotionAdapter() {
        @Override
        public void mouseMoved(MouseEvent e) {
            setToolTipText(panel.getToolTipText(getHeight() - e.getY(), e
                    .getX()));
        }
    });
    setResizingAllowed(false);
    panel.setSize(getSize().height, getSize().width);
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:15,代码来源:TopTablePanel.java

示例11: getJTableOptions

import javax.swing.JTable; //导入方法依赖的package包/类
public static void getJTableOptions(final String name, final JTable table,
                                    final Properties properties) {
    final Integer colCount = getObjectInteger(name + "_col_count",
            properties);
    if (colCount == null || colCount.intValue() != table.getColumnCount())
        return;
    final String cNames[] = new String[table.getColumnCount()];
    final Object cols[] = new Object[table.getColumnCount()];

    for (int i = 0; i < cNames.length; i++) {
        cNames[i] = table.getColumnName(i);
        cols[i] = table.getColumnModel().getColumn(i);
    }

    for (final String element : cNames) {
        final int width = getInteger(name + "_col_" + element + "_width",
                table.getColumn(element).getWidth(), properties);
        table.getColumn(element).setPreferredWidth(width);
    }

    final TableColumnModel cm = table.getColumnModel();
    final int tci[] = new int[cNames.length];
    for (int i = 0; i < cNames.length; i++)
        cm.removeColumn((TableColumn) cols[i]);

    for (int i = 0; i < cNames.length; i++) {
        tci[i] = getInteger(name + "_col_" + cNames[i] + "_index", i,
                properties);
    }

    for (int i = 0; i < cNames.length; i++)
        for (int j = 0; j < cNames.length; j++)
            if (tci[j] == i)
                cm.addColumn((TableColumn) cols[j]);

}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:37,代码来源:Options.java

示例12: PanelCourses

import javax.swing.JTable; //导入方法依赖的package包/类
public PanelCourses(Student student,CourseOutline courseoutline) throws Exception{
	this.co=courseoutline;
	setLayout(new BorderLayout(0, 0));
	cmdao=new CourseMappingDAO();
	/*JScrollPane scrollPane = new JScrollPane();
	add(scrollPane, BorderLayout.CENTER);*/
	
	JLabel lblCoursesTaken = new JLabel("Courses Taken");
	//scrollPane.setColumnHeaderView(lblCoursesTaken);
	
	StudentCourseOutlineDAO sctodao = new StudentCourseOutlineDAO(student);
	ArrayList<String> course = sctodao.Coursedata(student);
      /* DefaultListModel<String> model = new DefaultListModel<>();
	int size = course.size();
	for(int i=0; i<size; i++){
    	model.addElement(course.get(i));
	}
	JList list = new JList(model);
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	list.addListSelectionListener(new ListSelectionListener() {
		public void valueChanged(ListSelectionEvent arg0) {
			String course_name=(String)list.getSelectedValue();
			//System.out.println("Course id is::"+course_name);
			//System.out.println("Batch is ::"+student.getBatch());
			String path=cmdao.getDirectoryPath(course_name, student.getBatch());
			
			//System.out.println("Path is::"+path);
			//System.out.println(path);
			co.c_panel.curr_subject=course_name;
			try {
				co.c_panel.resetPanes(student, path);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 jb=(JLabel)co.panel.getComponent(7);
			 jb_c=(JLabel)co.panel.getComponent(6);
			jb.setVisible(true);
			jb_c.setVisible(true);
			jb.setText(course_name);
			CardLayout card=(CardLayout)co.panel_1.getLayout();
			co.panel_2.getComponent(0).setEnabled(true);
			card.show(co.panel_1, "CoursePanel");
		}
	});
	scrollPane.setViewportView(list);*/
	
	TableCellRenderer buttonRenderer = new ButtonRenderer();
	model=new CourseTableModel(course,this,student);
	table = new JTable();
	table.setRowHeight(30);
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.setDefaultRenderer(JButton.class,buttonRenderer);
	table.addMouseListener(new JTableButtonMouseListener(table));
	table.setModel(model);
	JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	//resizeColumnWidth(table);
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	TableColumnModel tcm = table.getColumnModel();
	tcm.getColumn(0).setPreferredWidth(800);    
	tcm.getColumn(1).setPreferredWidth(200);    
	
	
	scrollPane.setBounds(10, 57, 1320, 450);
	scrollPane.setColumnHeaderView(lblCoursesTaken);
	add(scrollPane, BorderLayout.CENTER);
	
	
}
 
开发者ID:jtatia,项目名称:Course-Management-System,代码行数:70,代码来源:PanelCourses.java

示例13: getJTableOptions

import javax.swing.JTable; //导入方法依赖的package包/类
public static void getJTableOptions(final String name, final JTable table,
                                    final Properties properties) {
    final Integer colCount = getObjectInteger(name + "_col_count",
            properties);
    if (colCount == null || colCount.intValue() != table.getColumnCount())
        return;
    final Object cols[] = new Object[table.getColumnCount()];

    for (int i = 0; i < colCount.intValue(); i++) {
        cols[i] = table.getColumnModel().getColumn(
                table.convertColumnIndexToView(i));
    }

    for (int i = 0; i < colCount.intValue(); i++) {
        try {
            int index = table.convertColumnIndexToView(i);
            final int width = getInteger(name + "_col_" + i + "_width",
                    table.getColumnModel().getColumn(index).getWidth(),
                    properties);
            table.getColumnModel().getColumn(index)
                    .setPreferredWidth(width);
        } catch (Exception e) {

        }
    }

    final TableColumnModel cm = table.getColumnModel();
    final int tci[] = new int[colCount.intValue()];
    for (int i = 0; i < colCount.intValue(); i++)
        cm.removeColumn((TableColumn) cols[i]);

    for (int i = 0; i < colCount.intValue(); i++) {
        tci[i] = getInteger(name + "_col_" + i + "_index", i, properties);
    }

    for (int i = 0; i < colCount.intValue(); i++)
        for (int j = 0; j < colCount.intValue(); j++)
            if (tci[j] == i)
                cm.addColumn((TableColumn) cols[j]);

}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:42,代码来源:Options.java

示例14: LogTableManager

import javax.swing.JTable; //导入方法依赖的package包/类
public LogTableManager(JTable table) {
    this.table = table;
    this.model = (LogTableModel) table.getModel();
    this.columnModel = table.getColumnModel();
    initTable();
}
 
开发者ID:NBANDROIDTEAM,项目名称:NBANDROID-V2,代码行数:7,代码来源:LogTableManager.java


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