List of usage examples for javax.swing DefaultBoundedRangeModel setValue
public void setValue(int n)
From source file:Main.java
public static void main(String args[]) { DefaultBoundedRangeModel model = new DefaultBoundedRangeModel(); model.setValue(100); }
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
private void setupKeyActionsForResultPanelVerticalScrollBar() { // maps the default key strokes for JTable to set the vertical scrollbar, so we can intervent: final InputMap inputmap = getResultTable().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, InputEvent.CTRL_MASK), "last"); inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "nextrow"); inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "nextpage"); final JScrollBar scrlbarVertical = getResultPanel().getResultTableScrollPane().getVerticalScrollBar(); final DefaultBoundedRangeModel model = (DefaultBoundedRangeModel) scrlbarVertical.getModel(); getResultTable().getActionMap().put("last", new AbstractAction() { @Override//w w w. jav a 2s.c o m public void actionPerformed(ActionEvent ev) { final int iSupposedValue = model.getMaximum() - model.getExtent(); model.setValue(iSupposedValue); // this causes the necessary rows to be loaded. Loading may be cancelled by the user. LOG.debug("NOW it's time to select the row..."); if (model.getValue() == iSupposedValue) getCollectNavigationModel().selectLastElement(); } }); getResultTable().getActionMap().put("nextrow", new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { final int iSelectedRow = getResultTable().getSelectedRow(); final int iLastVisibleRow = TableUtils.getLastVisibleRow(getResultTable()); if (iSelectedRow + 1 < iLastVisibleRow) { // next row is still visible: just select it: if (!getCollectNavigationModel().isLastElementSelected()) getCollectNavigationModel().selectNextElement(); } else { // we have to move the viewport before we can select the next row: final int iSupposedValue = Math.min(model.getValue() + getResultTable().getRowHeight(), model.getMaximum() - model.getExtent()); model.setValue(iSupposedValue); // this causes the necessary rows to be loaded. Loading may be cancelled by the user. LOG.debug("NOW it's time to select the row..."); if (model.getValue() == iSupposedValue) if (!getCollectNavigationModel().isLastElementSelected()) getCollectNavigationModel().selectNextElement(); } } }); getResultTable().getActionMap().put("nextpage", new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { final int iSupposedValue = Math.min(model.getValue() + model.getExtent(), model.getMaximum() - model.getExtent()); model.setValue(iSupposedValue); // this causes the necessary rows to be loaded. Loading may be cancelled by the user. LOG.debug("NOW it's time to select the row..."); if (model.getValue() == iSupposedValue) { final int iShiftRowCount = (int) Math .ceil((double) model.getExtent() / (double) getResultTable().getRowHeight()); final int iRow = Math.min( getResultTable().getSelectionModel().getAnchorSelectionIndex() + iShiftRowCount, getResultTable().getRowCount() - 1); getResultTable().setRowSelectionInterval(iRow, iRow); } } }); final Action actShowLogBook = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { cmdShowLogBook(); getDetailsPanel().grabFocus(); } }; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SHOW_LOGBOOK, actShowLogBook, getDetailsPanel()); final Action actShowStateHistory = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { cmdShowStateHistory(); getDetailsPanel().grabFocus(); } }; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SHOW_STATE_HISTORIE, actShowStateHistory, getDetailsPanel()); final Action actPrintCurrentGenericObject = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { cmdPrintCurrentGenericObject(); getDetailsPanel().grabFocus(); } }; KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PRINT_LEASED_OBJECT, actPrintCurrentGenericObject, getDetailsPanel()); }