2
觀察::如何使滾動窗格靜態?
只要用戶到達表格中的最後一個單元格並按下Tab鍵,焦點就會轉移到第一個單元格,即表格頂部。
帶來的表視圖回最後一個單元格,通過使用功能table.scrollRectToVisible(矩形),但由於該有動靜,看上去就像沒有在表中的值虛假變化。
該方案::如果我已使make Scroll窗格靜態在特定位置,以便我可以控制運動。如何才能使這成爲可能..
預先感謝您...
觀察::如何使滾動窗格靜態?
只要用戶到達表格中的最後一個單元格並按下Tab鍵,焦點就會轉移到第一個單元格,即表格頂部。
帶來的表視圖回最後一個單元格,通過使用功能table.scrollRectToVisible(矩形),但由於該有動靜,看上去就像沒有在表中的值虛假變化。
該方案::如果我已使make Scroll窗格靜態在特定位置,以便我可以控制運動。如何才能使這成爲可能..
預先感謝您...
的基本方法是換行表的默認導航行動納入其檢查當前單元格的自定義操作:如果這是最後,做否則沒有執行該包裹行動
代碼示例:
Object key = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.get(KeyStroke.getKeyStroke("ENTER"));
final Action action = table.getActionMap().get(key);
Action custom = new AbstractAction("wrap") {
@Override
public void actionPerformed(ActionEvent e) {
// implement your prevention logic
// here: don't perform if the current cell focus is the very cell of the table
int row = table.getSelectionModel().getLeadSelectionIndex();
if (row == table.getRowCount() - 1) {
int column = table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
if (column == table.getColumnCount() -1) {
// if so, do nothing and return
return;
}
}
// if not, call the original action
action.actionPerformed(e);
}
};
table.getActionMap().put(key, custom);
+1重用的默認操作。 – camickr