當前位置: 首頁>>代碼示例>>Java>>正文


Java JTableHeader.addMouseListener方法代碼示例

本文整理匯總了Java中javax.swing.table.JTableHeader.addMouseListener方法的典型用法代碼示例。如果您正苦於以下問題:Java JTableHeader.addMouseListener方法的具體用法?Java JTableHeader.addMouseListener怎麽用?Java JTableHeader.addMouseListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.table.JTableHeader的用法示例。


在下文中一共展示了JTableHeader.addMouseListener方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addMouseListenerToHeaderInTable

import javax.swing.table.JTableHeader; //導入方法依賴的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); 
}
 
開發者ID:ser316asu,項目名稱:Neukoelln_SER316,代碼行數:27,代碼來源:TableSorter.java

示例2: addMouseListenerToHeaderInTable

import javax.swing.table.JTableHeader; //導入方法依賴的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); 
}
 
開發者ID:ser316asu,項目名稱:SER316-Dresden,代碼行數:27,代碼來源:TableSorter.java

示例3: addMouseListenerToHeaderInTable

import javax.swing.table.JTableHeader; //導入方法依賴的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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:TableSorter.java

示例4: tableHeaderDuplicates

import javax.swing.table.JTableHeader; //導入方法依賴的package包/類
public void tableHeaderDuplicates() throws Throwable {
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override public void run() {
            tableHeader = (JTableHeader) ComponentUtils.findComponent(JTableHeader.class, frame);
            JTable table = (JTable) ComponentUtils.findComponent(JTable.class, frame);
            table.getColumnModel().getColumn(1).setHeaderValue("Movie Title");
            int columnIndex = 2; // Award Category
            Rectangle rect = tableHeader.getHeaderRect(columnIndex);
            p = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
        }
    });

    tableHeader.addMouseListener(new MouseAdapter() {
        @Override public void mousePressed(MouseEvent e) {
            RTableHeader rtableHeader = new RTableHeader(tableHeader, null, e.getPoint(), lr);
            rtableHeader.mouseButton1Pressed(e);
        }
    });

    IDevice device = Device.getDevice();
    device.click(tableHeader, Buttons.LEFT, 1, p.x, p.y);

    new Wait("Waiting for logging recorder callback") {
        @Override public boolean until() {
            return lr.getCalls().size() > 0;
        }
    };

    Call call = lr.getCall();
    AssertJUnit.assertEquals("click", call.getFunction());
    AssertJUnit.assertEquals("Movie Title(1)", call.getCellinfo());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:34,代碼來源:RTableHeaderTest.java

示例5: addMouseListenerToHeaderInTable

import javax.swing.table.JTableHeader; //導入方法依賴的package包/類
public void addMouseListenerToHeaderInTable(JTable table) {
    tableView = table;
    columnModel = tableView.getColumnModel();
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(this);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:TableSorter.java


注:本文中的javax.swing.table.JTableHeader.addMouseListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。