Java Code Examples for javax.swing.JTable#convertColumnIndexToModel()
The following examples show how to use
javax.swing.JTable#convertColumnIndexToModel() .
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: TableCheckBoxColumn.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 7 votes |
@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); } } } }
Example 2
Source File: MyCellRenderer.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Gets the table cell renderer component. * * @param table the table * @param value the value * @param isSelected the is selected * @param hasFocus the has focus * @param row the row * @param column the column * @param styleList the style list * @return the table cell renderer component */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column, ArrayList styleList) { Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); StyleMapEntry e = (StyleMapEntry) styleList.get(row); if (e != null) { int modelColumnNr = table.convertColumnIndexToModel(column); // if (modelColumnNr == StyleConstants.FEATURE_VALUE_COLUMN && // !table.getModel().isCellEditable(row, modelColumnNr)) // { // cell.setBackground(table.getParent().getBackground()); // ((JLabel) cell).setIcon(null); // } // else { ((JLabel) cell).setIcon(((modelColumnNr == 0 && isSelected) ? smallArrowIcon : null)); cell.setForeground(e.getForeground()); cell.setBackground(e.getBackground()); } } return cell; }
Example 3
Source File: TableSorter.java From jplag with GNU General Public License v3.0 | 6 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = tableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (c instanceof JLabel) { JLabel l = (JLabel) c; l.setHorizontalTextPosition(JLabel.LEFT); int modelColumn = table.convertColumnIndexToModel(column); l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize())); } return c; }
Example 4
Source File: TableSorter.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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); }
Example 5
Source File: TableSorter.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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); }
Example 6
Source File: TableSorter.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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); }
Example 7
Source File: JTableJavaElement.java From marathonv5 with Apache License 2.0 | 6 votes |
private void validate(int viewRow, int viewCol) { JTable table = (JTable) getComponent(); try { int row = table.convertRowIndexToModel(viewRow); int col = table.convertColumnIndexToModel(viewCol); TableModel model = table.getModel(); if (row >= 0 && row < model.getRowCount() && col >= 0 && col < model.getColumnCount()) { if (table.isCellEditable(viewRow, viewCol)) { return; } else { throw new NoSuchElementException( "The cell is not editable on JTable: (" + viewRow + ", " + viewCol + ")", null); } } } catch (IndexOutOfBoundsException e) { } throw new NoSuchElementException("Invalid row/col for JTable: (" + viewRow + ", " + viewCol + ")", null); }
Example 8
Source File: NumberFieldEditor.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row, int column) { oldValue = value; int modelColumn = table.convertColumnIndexToModel(column); TableModel tm = table.getModel(); dbColumn = null; if (tm instanceof ResultSetTableModel) { textField.setInputVerifier(verifier); dbColumn = ((ResultSetTableModel) tm).getColumn(modelColumn); } else { textField.setInputVerifier(null); } Component c = super.getTableCellEditorComponent(table, value, isSelected, row, column); if (suppressEditorBorder && c instanceof JComponent) { ((JComponent) c).setBorder(BorderFactory.createEmptyBorder()); } return c; }
Example 9
Source File: TableSorter.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); final MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { final TableColumnModel columnModel = tableView.getColumnModel(); final int viewColumn = columnModel.getColumnIndexAtX(e.getX()); final int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { final int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; final boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; final JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 10
Source File: TableSorter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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); }
Example 11
Source File: TableSorter.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); final MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { final TableColumnModel columnModel = tableView.getColumnModel(); final int viewColumn = columnModel.getColumnIndexAtX(e.getX()); final int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { //System.out.println("Sorting ..."); final int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; final boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; final JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 12
Source File: CTableSorter.java From binnavi with Apache License 2.0 | 5 votes |
@Override public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { final Component c = tableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (c instanceof JLabel) { final JLabel l = (JLabel) c; l.setHorizontalTextPosition(SwingConstants.LEFT); final int modelColumn = table.convertColumnIndexToModel(column); l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize())); } return c; }
Example 13
Source File: SortButtonRenderer.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Returns the renderer component. * * @param table the table. * @param value the value. * @param isSelected selected? * @param hasFocus focussed? * @param row the row. * @param column the column. * @return the renderer. */ public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { if (table == null) { throw new NullPointerException("Table must not be null."); } final JComponent component; final SortableTableModel model = (SortableTableModel) table.getModel(); final int cc = table.convertColumnIndexToModel(column); final boolean isSorting = (model.getSortingColumn() == cc); final boolean isAscending = model.isAscending(); final JTableHeader header = table.getTableHeader(); final boolean isPressed = (cc == this.pressedColumn); if (this.useLabels) { final JLabel label = getRendererLabel(isSorting, isAscending); label.setText((value == null) ? "" : value.toString()); component = label; } else { final JButton button = getRendererButton(isSorting, isAscending); button.setText((value == null) ? "" : value.toString()); button.getModel().setPressed(isPressed); button.getModel().setArmed(isPressed); component = button; } if (header != null) { component.setForeground(header.getForeground()); component.setBackground(header.getBackground()); component.setFont(header.getFont()); } return component; }
Example 14
Source File: StringTableCellEditor.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, final int column) { final JComponent c = (JComponent) super.getTableCellEditorComponent(table, value, isSelected, row, column); this.tableModel = table.getModel(); this.columnName = table.getColumnName(column); this.modelRow = table.convertRowIndexToModel(row); this.modelColumn = table.convertColumnIndexToModel(column); this.tc = c instanceof JTextComponent ? (JTextComponent) c : null; JPanel panel = new JPanel(new BorderLayout()) { @Override public void addNotify() { super.addNotify(); c.requestFocus(); } }; panel.add(c); if (suppressEditorBorder) { c.setBorder(BorderFactory.createEmptyBorder()); } panel.add(customEditorButton, BorderLayout.EAST); panel.revalidate(); panel.repaint(); return panel; }
Example 15
Source File: GitStatusTable.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component renderer; int modelColumnIndex = table.convertColumnIndexToModel(column); GitStatusNode node = null; if (modelColumnIndex == 0) { node = tableModel.getNode(table.convertRowIndexToModel(row)); if (!isSelected) { value = node.getHtmlDisplayName(); } if (GitModuleConfig.getDefault().isExcludedFromCommit(node.getFile().getAbsolutePath())) { value = "<s>" + value + "</s>"; //NOI18N } value = "<html>" + value; // NOI18N } if (modelColumnIndex == 2) { renderer = pathRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } else { renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } if (renderer instanceof JComponent) { if (node == null) { node = tableModel.getNode(table.convertRowIndexToModel(row)); } String path = node.getFile().getAbsolutePath(); ((JComponent) renderer).setToolTipText(path); } return renderer; }
Example 16
Source File: TableViewTopComponent.java From constellation with Apache License 2.0 | 5 votes |
@Override public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { final Component c = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (c instanceof JLabel) { final GraphTableModel model = (GraphTableModel) table.getModel(); final int modelIndex = table.convertColumnIndexToModel(column); final Segment segment = model.getSegment(modelIndex); final JLabel label = (JLabel) c; label.setIcon(segment == Segment.TX ? UserInterfaceIconProvider.CONNECTIONS.buildIcon(16) : VX_ICON); label.setHorizontalTextPosition(SwingConstants.RIGHT); } return c; }
Example 17
Source File: ItemValueRenderer.java From visualvm with GNU General Public License v2.0 | 5 votes |
protected Object formatValue(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { DetailsTableModel model = (DetailsTableModel)table.getModel(); int columnIndex = table.convertColumnIndexToModel(column); ValueItemDescriptor descriptor = model.getDescriptor(columnIndex); String valueString = descriptor.getValueString((Long)value, ItemValueFormatter.FORMAT_DETAILS); // Improve spacing of the text return " " + valueString + " "; // NOI18N }
Example 18
Source File: SortableAndSearchableWrapperTableModel.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Adds a mouselistener to the header: left-click on the header sorts in * ascending manner, using shift-left-click in descending manner. * * @param table the table to add the listener to */ public void addMouseListenerToHeader(JTable table) { final SortableAndSearchableWrapperTableModel fModel; final JTable fTable; JTableHeader header; fModel = this; fTable = table; fTable.setColumnSelectionAllowed(false); header = fTable.getTableHeader(); if (header != null) { if (m_MouseListener == null) { m_MouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = fTable.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = fTable.convertColumnIndexToModel(viewColumn); if (MouseUtils.isLeftClick(e) && !e.isAltDown() && !e.isControlDown() && (column != -1)) fModel.sort(column, !e.isShiftDown()); } }; } header.addMouseListener(m_MouseListener); } }
Example 19
Source File: TableViewTopComponent.java From constellation with Apache License 2.0 | 5 votes |
@Override public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (!isSelected) { final GraphTableModel model = (GraphTableModel) table.getModel(); final int modelIndex = table.convertColumnIndexToModel(column); final Segment segment = model.getSegment(modelIndex); c.setBackground(SEGMENT_COLORS[segment.ordinal()]); } return c; }
Example 20
Source File: SeaGlassTableHeaderUI.java From seaglass with Apache License 2.0 | 4 votes |
/** * @see com.seaglasslookandfeel.ui.SeaGlassTableHeaderUI$DefaultTableCellHeaderRenderer#getTableCellRendererComponent(javax.swing.JTable, * java.lang.Object, boolean, boolean, int, int) */ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { boolean hasRollover = false; // (column == getRolloverColumn()); if (isSelected || hasRollover || hasFocus) { SeaGlassLookAndFeel.setSelectedUI((SeaGlassLabelUI) SeaGlassLookAndFeel.getUIOfType(getUI(), SeaGlassLabelUI.class), isSelected, hasFocus, table.isEnabled(), hasRollover); } else { SeaGlassLookAndFeel.resetSelectedUI(); } // Stuff a variable into the client property of this renderer // indicating the sort order, so that different rendering can be // done for the header based on sorted state. RowSorter rs = table == null ? null : table.getRowSorter(); java.util.List<? extends RowSorter.SortKey> sortKeys = rs == null ? null : rs.getSortKeys(); if (sortKeys != null && sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: putClientProperty("Table.sortOrder", "ASCENDING"); break; case DESCENDING: putClientProperty("Table.sortOrder", "DESCENDING"); break; case UNSORTED: putClientProperty("Table.sortOrder", "UNSORTED"); break; default: throw new AssertionError("Cannot happen"); } } else { putClientProperty("Table.sortOrder", "UNSORTED"); } super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); return this; }