本文整理汇总了Java中javax.swing.table.TableColumnModel.getColumnIndexAtX方法的典型用法代码示例。如果您正苦于以下问题:Java TableColumnModel.getColumnIndexAtX方法的具体用法?Java TableColumnModel.getColumnIndexAtX怎么用?Java TableColumnModel.getColumnIndexAtX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.TableColumnModel
的用法示例。
在下文中一共展示了TableColumnModel.getColumnIndexAtX方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseClicked
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING,
// DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether
// shift is pressed.
status = status + (e.isShiftDown() ? -1 : 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0,
// 1}
setSortingStatus(column, status);
}
}
示例2: addMouseListenerToHeaderInTable
import javax.swing.table.TableColumnModel; //导入方法依赖的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: mouseClicked
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
status = status + (e.isShiftDown() ? -1 : 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status);
}
}
示例4: mouseClicked
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
if (!e.isPopupTrigger()) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
if (columnModel.getColumn(viewColumn).getHeaderValue().equals("File Name")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_NAME, false);
FileTable.this.fileList.updateTableData();
} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals("Type")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_TYPE, false);
FileTable.this.fileList.updateTableData();
} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals("Last Modified")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_MODIFIED, false);
FileTable.this.fileList.updateTableData();
} else if (columnModel.getColumn(viewColumn).getHeaderValue().equals("Size")) {
FileTable.this.fileList.orderBy(FileList.ORDER_BY_FILE_SIZE, false);
FileTable.this.fileList.updateTableData();
}
}
}
}
示例5: mousePressed
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
super.mousePressed(e);
if (header.getResizingColumn() == null) {
Point p = e.getPoint();
TableColumnModel columnModel = header.getColumnModel();
int index = columnModel.getColumnIndexAtX(p.x);
if (index != -1) {
if (header.editCellAt(index, e)) {
setDispatchComponent(e);
repostEvent(e);
}
}
}
}
示例6: mouseMoved
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
@Override
public void mouseMoved(MouseEvent evt) {
TableColumn col = null;
JTableHeader header = (JTableHeader) evt.getSource();
JTable table = header.getTable();
TableColumnModel colModel = table.getColumnModel();
int vColIndex = colModel.getColumnIndexAtX(evt.getX());
// Return if not clicked on any column header
if (vColIndex >= 0) {
col = colModel.getColumn(vColIndex);
}
if (col != curCol) {
header.setToolTipText(tips.get(col));
curCol = col;
}
}
示例7: mouseClicked
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent evt) {
// XXX Benchmark sort performance
//long start = System.currentTimeMillis();
CommonUI.setWaitCursor(SwingUtilities.getRoot(table));
TableColumnModel columnModel = table.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(evt.getX());
int column = table.convertColumnIndexToModel(viewColumn);
if (evt.getClickCount() == 1 && column != -1) {
// Reverse the sorting direction.
model.sortByColumn(column, !model.isAscending());
}
// XXX Benchmark performance
// System.out.println("Sort time: " +
// (System.currentTimeMillis() - start));
CommonUI.setDefaultCursor(SwingUtilities.getRoot(table));
}
示例8: addMouseListenerToHeaderInTable
import javax.swing.table.TableColumnModel; //导入方法依赖的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);
}
示例9: addMouseListenerToHeaderInTable
import javax.swing.table.TableColumnModel; //导入方法依赖的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);
}
示例10: mouseClicked
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e)
{
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if( column != -1 )
{
int status = getSortingStatus(column);
if( !e.isControlDown() )
{
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING,
// DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether
// shift is pressed.
status = status + (e.isShiftDown() ? -1 : 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0,
// 1}
setSortingStatus(column, status);
}
}
示例11: mouseClicked
import javax.swing.table.TableColumnModel; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
status = status + (e.isShiftDown() ? -1
: 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status);
}
}