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

The following examples show how to use javax.swing.JTable#setFocusable() . 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: 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 3
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 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: 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 7
Source File: LanguageTableModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void initializeTable(JTable table)
{
	table.setCellSelectionEnabled(false);
	table.setRowSelectionAllowed(false);
	table.setColumnSelectionAllowed(false);
	table.setFocusable(false);
	table.setRowHeight(21);
	table.getTableHeader().setReorderingAllowed(false);
}
 
Example 8
Source File: LanguageTableModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void initializeTable(JTable table)
{
	table.setCellSelectionEnabled(false);
	table.setRowSelectionAllowed(false);
	table.setColumnSelectionAllowed(false);
	table.setFocusable(false);
	table.setRowHeight(21);
	table.getTableHeader().setReorderingAllowed(false);
}
 
Example 9
Source File: HeaderPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 10
Source File: HeaderPanel.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example 11
Source File: HeaderPanel.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example 12
Source File: EquipmentModels.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	EquipmentSetFacade equipSet = character.getEquipmentSetRef().get();
	List<EquipNode> paths = getSelectedEquipmentSetNodes();
	if (!paths.isEmpty())
	{
		Object[][] data = new Object[paths.size()][3];
		for (int i = 0; i < paths.size(); i++)
		{
			EquipNode path = paths.get(i);
			data[i][0] = path.getEquipment();
			data[i][1] = equipSet.getQuantity(path);
		}
		Object[] columns = {LanguageBundle.getString("in_equipItem"), //$NON-NLS-1$
			LanguageBundle.getString("in_equipQuantityAbbrev"), //$NON-NLS-1$
		};
		DefaultTableModel tableModel = new DefaultTableModel(data, columns)
		{

			@Override
			public Class<?> getColumnClass(int columnIndex)
			{
				if (columnIndex == 1)
				{
					return Integer.class;
				}
				return Object.class;
			}

			@Override
			public boolean isCellEditable(int row, int column)
			{
				return column != 0;
			}

		};
		JTable table = new JTable(tableModel);
		table.setFocusable(false);
		table.setCellSelectionEnabled(false);
		table.setDefaultRenderer(Integer.class, new TableCellUtilities.SpinnerRenderer());
		table.setDefaultEditor(Integer.class, new SpinnerEditor(equipSet.getEquippedItems()));
		table.setRowHeight(22);
		table.getColumnModel().getColumn(0).setPreferredWidth(140);
		table.getColumnModel().getColumn(1).setPreferredWidth(50);
		table.setPreferredScrollableViewportSize(table.getPreferredSize());
		JTableHeader header = table.getTableHeader();
		header.setReorderingAllowed(false);
		JScrollPane pane = EquipmentModels.prepareScrollPane(table);
		JPanel panel = new JPanel(new BorderLayout());
		JLabel help = new JLabel(LanguageBundle.getString("in_equipSelectUnequipQty")); //$NON-NLS-1$
		panel.add(help, BorderLayout.NORTH);
		panel.add(pane, BorderLayout.CENTER);
		int res = JOptionPane.showConfirmDialog(JOptionPane.getFrameForComponent(equipmentTable), panel,
			LanguageBundle.getString("in_equipUnequipSel"), //$NON-NLS-1$
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

		if (res == JOptionPane.OK_OPTION)
		{
			for (int i = 0; i < paths.size(); i++)
			{
				equipSet.removeEquipment(paths.get(i), (Integer) tableModel.getValueAt(i, 1));
			}
		}
	}
}
 
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);
}
 
Example 14
Source File: EquipmentModels.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	EquipmentSetFacade equipSet = character.getEquipmentSetRef().get();
	List<EquipNode> paths = getSelectedEquipmentSetNodes();
	if (!paths.isEmpty())
	{
		Object[][] data = new Object[paths.size()][3];
		for (int i = 0; i < paths.size(); i++)
		{
			EquipNode path = paths.get(i);
			data[i][0] = path.getEquipment();
			data[i][1] = equipSet.getQuantity(path);
		}
		Object[] columns = {LanguageBundle.getString("in_equipItem"), //$NON-NLS-1$
			LanguageBundle.getString("in_equipQuantityAbbrev"), //$NON-NLS-1$
		};
		DefaultTableModel tableModel = new DefaultTableModel(data, columns)
		{

			@Override
			public Class<?> getColumnClass(int columnIndex)
			{
				if (columnIndex == 1)
				{
					return Integer.class;
				}
				return Object.class;
			}

			@Override
			public boolean isCellEditable(int row, int column)
			{
				return column != 0;
			}

		};
		JTable table = new JTable(tableModel);
		table.setFocusable(false);
		table.setCellSelectionEnabled(false);
		table.setDefaultRenderer(Integer.class, new TableCellUtilities.SpinnerRenderer());
		table.setDefaultEditor(Integer.class, new SpinnerEditor(equipSet.getEquippedItems()));
		table.setRowHeight(22);
		table.getColumnModel().getColumn(0).setPreferredWidth(140);
		table.getColumnModel().getColumn(1).setPreferredWidth(50);
		table.setPreferredScrollableViewportSize(table.getPreferredSize());
		JTableHeader header = table.getTableHeader();
		header.setReorderingAllowed(false);
		JScrollPane pane = EquipmentModels.prepareScrollPane(table);
		JPanel panel = new JPanel(new BorderLayout());
		JLabel help = new JLabel(LanguageBundle.getString("in_equipSelectUnequipQty")); //$NON-NLS-1$
		panel.add(help, BorderLayout.NORTH);
		panel.add(pane, BorderLayout.CENTER);
		int res = JOptionPane.showConfirmDialog(JOptionPane.getFrameForComponent(equipmentTable), panel,
			LanguageBundle.getString("in_equipUnequipSel"), //$NON-NLS-1$
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

		if (res == JOptionPane.OK_OPTION)
		{
			for (int i = 0; i < paths.size(); i++)
			{
				equipSet.removeEquipment(paths.get(i), (Integer) tableModel.getValueAt(i, 1));
			}
		}
	}
}
 
Example 15
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);
}