本文整理匯總了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);
}
}