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

The following examples show how to use javax.swing.JTable#setAutoCreateColumnsFromModel() . 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: TaskList.java    From swift-k with Apache License 2.0 8 votes vote down vote up
public TaskList(TaskHandler handler) {
	this();
	this.handler = handler;
	model = new SingleHandlerTaskModel(handler);
	table = new JTable(model);
	table.setAutoCreateColumnsFromModel(true);
	table.setDefaultRenderer(String.class, new DefaultTableCellRenderer());
	getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
	update(0,0);
	table.setSize(640,200);
	table.setPreferredSize(new Dimension(640, 200));
	pack();
}
 
Example 2
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 3
Source File: StatisticsPanel.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
private JPanel createStatsTable(String title, Map<String, String> data) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(new JLabel(title), BorderLayout.PAGE_START);
    StatisticsModel model = new StatisticsModel();
    model.setData(data);
    JTable table = new JTable(model);
    table.setAutoCreateColumnsFromModel(true);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    table.setAutoCreateRowSorter(true);
    JScrollPane scrollPane = new JScrollPane(table);
    table.addNotify();
    scrollPane.getViewport().setOpaque(false);
    scrollPane.getColumnHeader().setOpaque(false);
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(300, (data.size()+2)*17));
    return panel;
}
 
Example 4
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 5
Source File: TableUtils.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static JScrollPane createToggleButtonSelectionPane(JTable table, JTable rowheaderTable,
	JToggleButton button)
{
	rowheaderTable.setAutoCreateColumnsFromModel(false);
	// force the tables to share models
	rowheaderTable.setModel(table.getModel());
	rowheaderTable.setSelectionModel(table.getSelectionModel());
	rowheaderTable.setRowHeight(table.getRowHeight());
	rowheaderTable.setIntercellSpacing(table.getIntercellSpacing());
	rowheaderTable.setShowGrid(false);
	rowheaderTable.setFocusable(false);

	TableColumn column = new TableColumn(-1);
	column.setHeaderValue(new Object());
	column.setCellRenderer(new TableCellUtilities.ToggleButtonRenderer(button));
	rowheaderTable.addColumn(column);
	rowheaderTable.setPreferredScrollableViewportSize(new Dimension(20, 0));

	JScrollPane scrollPane = new JScrollPane();
	scrollPane.setViewportView(table);
	scrollPane.setRowHeaderView(rowheaderTable);
	return scrollPane;
}
 
Example 6
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 7
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 8
Source File: TableUtils.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static JScrollPane createToggleButtonSelectionPane(JTable table, JTable rowheaderTable,
	JToggleButton button)
{
	rowheaderTable.setAutoCreateColumnsFromModel(false);
	// force the tables to share models
	rowheaderTable.setModel(table.getModel());
	rowheaderTable.setSelectionModel(table.getSelectionModel());
	rowheaderTable.setRowHeight(table.getRowHeight());
	rowheaderTable.setIntercellSpacing(table.getIntercellSpacing());
	rowheaderTable.setShowGrid(false);
	rowheaderTable.setFocusable(false);

	TableColumn column = new TableColumn(-1);
	column.setHeaderValue(new Object());
	column.setCellRenderer(new TableCellUtilities.ToggleButtonRenderer(button));
	rowheaderTable.addColumn(column);
	rowheaderTable.setPreferredScrollableViewportSize(new Dimension(20, 0));

	JScrollPane scrollPane = new JScrollPane();
	scrollPane.setViewportView(table);
	scrollPane.setRowHeaderView(rowheaderTable);
	return scrollPane;
}
 
Example 9
Source File: TaskList.java    From swift-k with Apache License 2.0 5 votes vote down vote up
public TaskList(List handlers) {
	this();
	this.handlers = handlers;
	model = new MultipleHandlerTaskModel(handlers);
	table = new JTable(model);
	table.setAutoCreateColumnsFromModel(true);
	table.setDefaultRenderer(String.class, new DefaultTableCellRenderer());
	getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
	update(0,0);
	table.setSize(640,200);
	table.setPreferredSize(new Dimension(640, 200));
	pack();
}
 
Example 10
Source File: AccountsPanel.java    From btdex with GNU General Public License v3.0 4 votes vote down vote up
public AccountsPanel(Main main) {
	super(new BorderLayout());

	this.main = main;

	table = new JTable(model = new DefaultTableModel(COLUMN_NAMES, 0));
	for (int i = 0; i < COLUMN_NAMES.length; i++) {
		table.getColumnModel().getColumn(i).setHeaderValue(tr(COLUMN_NAMES[i]));
	}
	table.setRowHeight(table.getRowHeight()+7);
	table.setPreferredScrollableViewportSize(new Dimension(400, 200));
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.getSelectionModel().addListSelectionListener(this);

	left = new JPanel(new BorderLayout());
	right = new JPanel();
	right.setVisible(false);
	right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));

	left.setBorder(BorderFactory.createTitledBorder(tr("acc_your_accounts")));
	right.setBorder(BorderFactory.createTitledBorder(tr("acc_account_details")));

	JScrollPane scrollPane = new JScrollPane(table);
	table.setFillsViewportHeight(true);

	// Center header and all columns
	DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
	centerRenderer.setHorizontalAlignment( JLabel.CENTER );
	for (int i = 0; i < table.getColumnCount(); i++) {
		table.getColumnModel().getColumn(i).setCellRenderer( centerRenderer );			
	}
	JTableHeader jtableHeader = table.getTableHeader();
	DefaultTableCellRenderer rend = (DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer();
	rend.setHorizontalAlignment(JLabel.CENTER);
	jtableHeader.setDefaultRenderer(rend);

	table.setAutoCreateColumnsFromModel(false);
	table.getColumnModel().getColumn(COL_NAME).setPreferredWidth(200);
	table.getColumnModel().getColumn(COL_MARKET).setPreferredWidth(20);

	JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
	left.add(buttonPane, BorderLayout.PAGE_END);

	addButton = new JButton(tr("acc_add_button"));
	removeButton = new JButton(tr("acc_remove_button"));
	removeButton.setEnabled(false);

	addButton.addActionListener(this);
	removeButton.addActionListener(this);

	buttonPane.add(addButton);
	buttonPane.add(removeButton);

	marketComboBox = new JComboBox<Market>();
	for(Market m : Markets.getMarkets()) {
		if(m.getTokenID()!=null)
			continue;
		marketComboBox.addItem(m);
	}
	marketComboBox.addActionListener(this);

	JPanel topPanel = new JPanel(new SpringLayout());
	topPanel.add(new Desc(tr("main_market"), marketComboBox), BorderLayout.LINE_START);
	topPanel.add(new Desc(tr("acc_alias"), nameField = new JTextField()), BorderLayout.CENTER);
	SpringUtilities.makeCompactGrid(topPanel, 1, 2, 0, 0, PAD, PAD);
	right.add(topPanel);

	formPanel = new JPanel(new SpringLayout());
	//		JScrollPane formScroll = new JScrollPane(formPanel);
	//		right.add(formScroll);
	right.add(formPanel);

	cancelButton = new JButton(tr("dlg_cancel"));
	okButton = new JButton(tr("dlg_ok"));

	cancelButton.addActionListener(this);
	okButton.addActionListener(this);
	rightButtonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
	rightButtonPane.add(cancelButton);
	rightButtonPane.add(okButton);
	right.add(rightButtonPane);

	add(left, BorderLayout.LINE_START);
	JPanel rightContainer = new JPanel(new BorderLayout());
	rightContainer.add(right, BorderLayout.PAGE_START);
	add(rightContainer, BorderLayout.CENTER);

	left.add(scrollPane, BorderLayout.CENTER);	

	loadAccounts();
}
 
Example 11
Source File: TransactionsPanel.java    From btdex with GNU General Public License v3.0 4 votes vote down vote up
public TransactionsPanel() {
	super(new BorderLayout());

	table = new JTable(model = new MyTableModel());
	table.setRowHeight(table.getRowHeight()+10);
	table.setRowSelectionAllowed(false);
	table.getTableHeader().setReorderingAllowed(false);
	
	copyIcon = IconFontSwing.buildIcon(Icons.COPY, 12, table.getForeground());
	expIcon = IconFontSwing.buildIcon(Icons.EXPLORER, 12, table.getForeground());

	JScrollPane scrollPane = new JScrollPane(table);
	table.setFillsViewportHeight(true);

	// Center header and all columns
	DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
	centerRenderer.setHorizontalAlignment( JLabel.CENTER );
	for (int i = 0; i < table.getColumnCount(); i++) {
		table.getColumnModel().getColumn(i).setCellRenderer( centerRenderer );			
	}
	JTableHeader jtableHeader = table.getTableHeader();
	DefaultTableCellRenderer rend = (DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer();
	rend.setHorizontalAlignment(JLabel.CENTER);
	jtableHeader.setDefaultRenderer(rend);

	table.setAutoCreateColumnsFromModel(false);

	table.getColumnModel().getColumn(COL_ID).setCellRenderer(OrderBook.BUTTON_RENDERER);
	table.getColumnModel().getColumn(COL_ID).setCellEditor(OrderBook.BUTTON_EDITOR);
	table.getColumnModel().getColumn(COL_ACCOUNT).setCellRenderer(OrderBook.BUTTON_RENDERER);
	table.getColumnModel().getColumn(COL_ACCOUNT).setCellEditor(OrderBook.BUTTON_EDITOR);
	//
	table.getColumnModel().getColumn(COL_ACCOUNT).setPreferredWidth(200);
	table.getColumnModel().getColumn(COL_ID).setPreferredWidth(200);
	table.getColumnModel().getColumn(COL_TIME).setPreferredWidth(120);
	
	statusLabel = new JLabel(" ", JLabel.RIGHT);
	statusLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

	add(statusLabel, BorderLayout.PAGE_START);
	add(scrollPane, BorderLayout.CENTER);
}
 
Example 12
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 13
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);
}