本文整理汇总了Java中javax.swing.JTable.convertColumnIndexToModel方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.convertColumnIndexToModel方法的具体用法?Java JTable.convertColumnIndexToModel怎么用?Java JTable.convertColumnIndexToModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.convertColumnIndexToModel方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
示例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);
}
示例3: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
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;
}
示例4: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
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;
}
示例5: getTableCellEditorComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@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;
}
示例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);
}
}
}
}
示例7: 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) {
//Util.debug("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);
}
示例8: 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);
}
示例9: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component renderer;
int modelColumnIndex = table.convertColumnIndexToModel(column);
DiffNode node = null;
if (modelColumnIndex == 0) {
node = tableModel.getNode(table.convertRowIndexToModel(row));
String htmlDisplayName = DiffUtils.getHtmlDisplayName(node, isModified(node.getFile()), isSelected);
if (node.isExcluded()) {
htmlDisplayName = "<s>" + (htmlDisplayName == null ? node.getFileNode().getName() : htmlDisplayName) + "</s>"; //NOI18N
}
if (htmlDisplayName != null) {
value = "<html>" + htmlDisplayName; //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;
}
示例10: getTableCellEditorComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@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;
}
示例11: validateRowCol
import javax.swing.JTable; //导入方法依赖的package包/类
private void validateRowCol() {
JTable table = (JTable) parent.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()) {
return;
}
} catch (IndexOutOfBoundsException e) {
}
throw new NoSuchElementException("Invalid row/col for JTable: (" + viewRow + ", " + viewCol + ")", null);
}
示例12: getTableCellRendererComponent
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
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(SwingConstants.LEFT);
int modelColumn = table.convertColumnIndexToModel(column);
l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
}
return c;
}