Java Code Examples for javax.swing.JTable#setColumnModel()

The following examples show how to use javax.swing.JTable#setColumnModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkillPointTableModel.java    From pcgen with GNU Lesser General Public License v2.1 7 votes vote down vote up
public static void initializeTable(JTable table)
{
	table.setAutoCreateColumnsFromModel(false);
	JTableHeader header = table.getTableHeader();
	TableColumnModel columns = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = header.getDefaultRenderer();
	columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false));
	columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true));
	TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false);
	remainCol.setCellRenderer(new BoldNumberRenderer());
	columns.addColumn(remainCol);
	columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false));
	table.setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
	table.setColumnModel(columns);
	table.setFocusable(false);
	header.setReorderingAllowed(false);
	header.setResizingAllowed(false);
}
 
Example 2
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
/**
 * Overriding the default re-ordering functionality.<p>
 * Re-ordering allowed if both of the i.e <code>columnIndex,newIndex</code>
 * are outside the limit.
 *
 * @param table the target tmodel
 * @param lmt re-ordering limit
 */
public static void setReorderColumn(JTable table, final int lmt) {
    table.setColumnModel(new DefaultTableColumnModel() {
        private static final long serialVersionUID = 1L;

        @Override
        public void moveColumn(int columnIndex, int newIndex) {
            if (columnIndex <= lmt) {
                return;
            } else if (newIndex <= lmt) {
                return;
            }
            super.moveColumn(columnIndex, newIndex);
        }
    });
}
 
Example 3
Source File: ClassLevelTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void initializeTable(JTable classLevelTable)
{
	JTableHeader tableHeader = classLevelTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);
	TableColumnModel columnModel = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
	columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true));
	classLevelTable.setColumnModel(columnModel);
	classLevelTable.setAutoCreateColumnsFromModel(false);
	classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
	classLevelTable.setFocusable(false);
	classLevelTable.setCellSelectionEnabled(false);
	classLevelTable.setRowHeight(20);
}
 
Example 4
Source File: SkillPointTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void initializeTable(JTable table)
{
	table.setAutoCreateColumnsFromModel(false);
	JTableHeader header = table.getTableHeader();
	TableColumnModel columns = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = header.getDefaultRenderer();
	columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false));
	columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true));
	TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false);
	remainCol.setCellRenderer(new BoldNumberRenderer());
	columns.addColumn(remainCol);
	columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false));
	table.setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
	table.setColumnModel(columns);
	table.setFocusable(false);
	header.setReorderingAllowed(false);
	header.setResizingAllowed(false);
}
 
Example 5
Source File: ClassLevelTableModel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void initializeTable(JTable classLevelTable)
{
	JTableHeader tableHeader = classLevelTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);
	TableColumnModel columnModel = new DefaultTableColumnModel();
	TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer();
	columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false));
	columnModel.addColumn(Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true));
	classLevelTable.setColumnModel(columnModel);
	classLevelTable.setAutoCreateColumnsFromModel(false);
	classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
	classLevelTable.setFocusable(false);
	classLevelTable.setCellSelectionEnabled(false);
	classLevelTable.setRowHeight(20);
}
 
Example 6
Source File: RepoUsersTab.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public RepoUsersTab()
{
    _userTableModel = new UserTableModel();
    _userTableModel.addColumn(new TableColumn(0,75,null,new UserTableCellEditor()));
    _userTable = new JTable();
    _userTable.setColumnModel(_userTableModel);
    //this.add(_userTable);
}
 
Example 7
Source File: TableDemo.java    From littleluck with Apache License 2.0 4 votes vote down vote up
protected void initComponents() {
    setLayout(new BorderLayout());

    controlPanel = createControlPanel();
    add(controlPanel, BorderLayout.NORTH);

    //<snip>Create JTable
    oscarTable = new JTable(oscarModel);
    //</snip>

    //</snip>Set JTable display properties
    oscarTable.setColumnModel(createColumnModel());
    oscarTable.setAutoCreateRowSorter(true);
    oscarTable.setRowHeight(26);
    oscarTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    oscarTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    oscarTable.setIntercellSpacing(new Dimension(0, 0));
    //</snip>

    //<snip>Initialize preferred size for table's viewable area
    Dimension viewSize = new Dimension();
    viewSize.width = oscarTable.getColumnModel().getTotalColumnWidth();
    viewSize.height = 10 * oscarTable.getRowHeight();
    oscarTable.setPreferredScrollableViewportSize(viewSize);
    //</snip>

    //<snip>Customize height and alignment of table header
    JTableHeader header = oscarTable.getTableHeader();
    header.setPreferredSize(new Dimension(30, 26));
    TableCellRenderer headerRenderer = header.getDefaultRenderer();
    if (headerRenderer instanceof JLabel) {
        ((JLabel) headerRenderer).setHorizontalAlignment(JLabel.CENTER);
    }
    //</snip>

    LuckScrollPane scrollpane = new LuckScrollPane(oscarTable);
    dataPanel = new Stacker(scrollpane);
    add(dataPanel, BorderLayout.CENTER);

    add(createStatusBar(), BorderLayout.SOUTH);

}
 
Example 8
Source File: TableDemo.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
protected void initComponents() {
	setLayout(new BorderLayout());

	controlPanel = createControlPanel();
	add(controlPanel, BorderLayout.NORTH);

	// <snip>Create JTable
	oscarTable = new JTable(oscarModel);
	// </snip>

	// </snip>Set JTable display properties
	oscarTable.setColumnModel(createColumnModel());
	oscarTable.setAutoCreateRowSorter(true);
	oscarTable.setRowHeight(26);
	oscarTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
	oscarTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	oscarTable.setIntercellSpacing(new Dimension(0, 0));
	// </snip>

	// <snip>Initialize preferred size for table's viewable area
	Dimension viewSize = new Dimension();
	viewSize.width = oscarTable.getColumnModel().getTotalColumnWidth();
	viewSize.height = 10 * oscarTable.getRowHeight();
	oscarTable.setPreferredScrollableViewportSize(viewSize);
	// </snip>

	// <snip>Customize height and alignment of table header
	JTableHeader header = oscarTable.getTableHeader();
	header.setPreferredSize(new Dimension(30, 26));
	TableCellRenderer headerRenderer = header.getDefaultRenderer();
	if (headerRenderer instanceof JLabel) {
		((JLabel) headerRenderer).setHorizontalAlignment(JLabel.CENTER);
	}
	// </snip>

	JScrollPane scrollpane = new JScrollPane(oscarTable);
	dataPanel = new Stacker(scrollpane);
	add(dataPanel, BorderLayout.CENTER);

	add(createStatusBar(), BorderLayout.SOUTH);

}
 
Example 9
Source File: StatTableModel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void initializeTable(JTable statsTable)
{
	JTableHeader tableHeader = statsTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);

	statsTable.setAutoCreateColumnsFromModel(false);
	DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
	{
		TableColumn column =
				Utilities.createTableColumn(ABILITY_NAME, "Ability", new AbilityHeaderCellRenderer(), true);
		column.setIdentifier(ABILITY_COLUMN_ID);
		columnModel.addColumn(column);

		String htmlText = "<html><div align=\"center\">Final<br>Score</div></html>";
		column = Utilities.createTableColumn(FINAL_ABILITY_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setCellRenderer(new ValueRenderer());
		columnModel.addColumn(column);

		TableCellRenderer renderer = new ModRenderer();
		htmlText = "<html><div align=\"center\">Ability<br>Mod</div></html>";
		column = Utilities.createTableColumn(ABILITY_MOD, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Editable<br>Score</div></html>";
		column = Utilities.createTableColumn(EDITABLE_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setIdentifier(EDITABLE_COLUMN_ID);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Race<br>Adj</div></html>";
		column = Utilities.createTableColumn(RACE_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Misc<br>Adj</div></html>";
		column = Utilities.createTableColumn(MISC_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);
	}
	statsTable.setColumnModel(columnModel);
	statsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	statsTable.setShowVerticalLines(false);
	statsTable.setCellSelectionEnabled(false);
	statsTable.setFocusable(false);
	// XXX this should be calculated relative to font size and the size of a jspinner
	statsTable.setRowHeight(27);
	statsTable.setOpaque(false);
	tableHeader.setFont(FontManipulation.title(statsTable.getFont()));
	FontManipulation.large(statsTable);
}
 
Example 10
Source File: StatTableModel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void initializeTable(JTable statsTable)
{
	JTableHeader tableHeader = statsTable.getTableHeader();
	tableHeader.setResizingAllowed(false);
	tableHeader.setReorderingAllowed(false);

	statsTable.setAutoCreateColumnsFromModel(false);
	DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
	{
		TableColumn column =
				Utilities.createTableColumn(ABILITY_NAME, "Ability", new AbilityHeaderCellRenderer(), true);
		column.setIdentifier(ABILITY_COLUMN_ID);
		columnModel.addColumn(column);

		String htmlText = "<html><div align=\"center\">Final<br>Score</div></html>";
		column = Utilities.createTableColumn(FINAL_ABILITY_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setCellRenderer(new ValueRenderer());
		columnModel.addColumn(column);

		TableCellRenderer renderer = new ModRenderer();
		htmlText = "<html><div align=\"center\">Ability<br>Mod</div></html>";
		column = Utilities.createTableColumn(ABILITY_MOD, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Editable<br>Score</div></html>";
		column = Utilities.createTableColumn(EDITABLE_SCORE, htmlText, new FixedHeaderCellRenderer(htmlText),
			false);
		column.setIdentifier(EDITABLE_COLUMN_ID);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Race<br>Adj</div></html>";
		column = Utilities.createTableColumn(RACE_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);

		htmlText = "<html><div align=\"center\">Misc<br>Adj</div></html>";
		column = Utilities.createTableColumn(MISC_ADJ, htmlText, new FixedHeaderCellRenderer(htmlText), false);
		column.setCellRenderer(renderer);
		columnModel.addColumn(column);
	}
	statsTable.setColumnModel(columnModel);
	statsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	statsTable.setShowVerticalLines(false);
	statsTable.setCellSelectionEnabled(false);
	statsTable.setFocusable(false);
	// XXX this should be calculated relative to font size and the size of a jspinner
	statsTable.setRowHeight(27);
	statsTable.setOpaque(false);
	tableHeader.setFont(FontManipulation.title(statsTable.getFont()));
	FontManipulation.large(statsTable);
}