public void setZoom(float zoom) { if (!SwingUtilities.isEventDispatchThread()) { throw new IllegalStateException("Must be on EDT"); } if (zoom == zoom && zoom > 0.01 && Math.abs(zoom - this.zoom) > 0.01) { JScrollBar hsb = scrollPane.getHorizontalScrollBar(); JScrollBar vsb = scrollPane.getVerticalScrollBar(); float hv = (float) hsb.getValue(); float vv = (float) vsb.getValue(); float hm = (float) hsb.getMaximum(); float vm = (float) vsb.getMaximum(); this.zoom = zoom; view.setSize(view.getPreferredSize()); listener.setEnabled(false); // don't send adjustment events Dimension viewsize = view.getSize(); hv *= ((float) viewsize.width) / hm; vv *= ((float) viewsize.height) / vm; hsb.setMaximum(viewsize.width); vsb.setMaximum(viewsize.height); hsb.setValue(Math.round(hv)); vsb.setValue(Math.round(vv)); listener.setEnabled(true); view.revalidate(); view.repaint(); } }
public void paintViewport(Graphics g, JViewport c) { if (!browser.isPreviewColumnFilled()) { Dimension vs = c.getSize(); Dimension bs = browser.getSize(); JScrollBar vb = getVerticalBar(); g.setColor(Color.black); Dimension ss = vb.getPreferredSize(); // Paint scroll bar tracks at the right to fill the viewport if (bs.width < vs.width) { int fixedCellWidth = browser.getFixedCellWidth(); // FIXME - Apparently we have to do layout manually, because // invoking cellRendererPane.paneComponent with // "shouldValidate" set to true does not appear to have // the desired effect. try { vb.setSize(ss.width, vs.height); vb.doLayout(); } catch (NullPointerException e) { // We get NPE here in JDK 1.3. We ignore it. } for (int x = browser.getWidth() + fixedCellWidth; x < vs.width; x += fixedCellWidth + ss.width) { getCellRendererPane().paintComponent(g, vb, c, x, 0, ss.width, vs.height, false); } } } }
/** * Reverses configuration which was done on the specified component during installUI. This method * is invoked when this UIComponent instance is being removed as the UI delegate for the specified * component. This method should undo the configuration performed in installUI, being careful to * leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific * property objects, etc.). This should include the following: 1. Remove any UI-set borders from * the component. 2. Remove any UI-set layout managers on the component. 3. Remove any UI-added * sub-components from the component. 4. Remove any UI-added event/property listeners from the * component. 5. Remove any UI-installed keyboard UI from the component. 6. Nullify any allocated * instance data objects to allow for GC. * * @param c - the component to uninstall the ui on */ public void uninstallUI(JComponent c) { JScrollBar hsb = scrollpane.getHorizontalScrollBar(); hsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, null); JScrollBar vsb = scrollpane.getVerticalScrollBar(); vsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, null); super.uninstallUI(c); }
public void mouseWheelMoved(MouseWheelEvent e) { String st[] = {"PER UNITA'", "PER BLOCCO"}; int unit = e.getUnitsToScroll(); // calcolo per la scrollbar verticale l'attuale posizione // e l'unità di incremento per scroll JScrollBar sb = sp.getVerticalScrollBar(); int y = sb.getValue(); int y1 = e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ? sb.getUnitIncrement(1) : sb.getBlockIncrement(1); sb.setValue(y + y1 * unit); // aggiorna la view della textarea int a = e.getScrollAmount(); int b = e.getScrollType(); int c = e.getUnitsToScroll(); int d = e.getWheelRotation(); double f = e.getPreciseWheelRotation(); String g = "Unità da scorrere per giro di tacca: " + a + "\nTipo di scroll: " + st[e.getScrollType()] + "\nUnità che scorreranno verso l'alto: " + c + "\nNumero di tacche ruotate: " + d + "\nNumero di tacche precisamente ruotate: " + f; wheel_area.setText(g); }
public TicketListView() { table = new TicketListTable(); table.setModel(tableModel = new TicketListTableModel()); table.setRowHeight(40); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setDefaultRenderer(Object.class, new PosTableRenderer()); table.setGridColor(Color.LIGHT_GRAY); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setPreferredWidth(20); columnModel.getColumn(1).setPreferredWidth(20); columnModel.getColumn(2).setPreferredWidth(200); columnModel.getColumn(3).setPreferredWidth(100); JScrollPane scrollPane = new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); scrollBar.setPreferredSize(new Dimension(30, 60)); setLayout(new BorderLayout()); add(scrollPane); }
/* * This method is called every time: * - to make sure the viewport is returned to its default position * - to remove the horizontal scrollbar when it is not wanted */ private void checkHorizontalScrollBar(BasicComboPopup popup) { // Reset the viewport to the left JViewport viewport = scrollPane.getViewport(); Point p = viewport.getViewPosition(); p.x = 0; viewport.setViewPosition(p); // Remove the scrollbar so it is never painted if (!scrollBarRequired) { scrollPane.setHorizontalScrollBar(null); return; } // Make sure a horizontal scrollbar exists in the scrollpane JScrollBar horizontal = scrollPane.getHorizontalScrollBar(); if (horizontal == null) { horizontal = new JScrollBar(JScrollBar.HORIZONTAL); scrollPane.setHorizontalScrollBar(horizontal); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); } // Potentially increase height of scroll pane to display the scrollbar if (horizontalScrollBarWillBeVisible(popup, scrollPane)) { Dimension scrollPaneSize = scrollPane.getPreferredSize(); scrollPaneSize.height += horizontal.getPreferredSize().height; scrollPane.setPreferredSize(scrollPaneSize); scrollPane.setMaximumSize(scrollPaneSize); scrollPane.revalidate(); } }
private void ensureRectIsInBounds(final Rectangle rectangle, final Dimension bounds) { if (rectangle.x < 0) { rectangle.x = 0; } if (rectangle.x + rectangle.width > bounds.width) { final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); final int scrollBarWidth; if (verticalScrollBar != null) { scrollBarWidth = verticalScrollBar.getWidth(); } else { scrollBarWidth = 0; } rectangle.x = bounds.width - rectangle.width - scrollBarWidth; } if (rectangle.y < 0) { rectangle.y = 0; } if (rectangle.y + rectangle.height > bounds.height) { final JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar(); final int scrollBarHeight; if (horizontalScrollBar != null) { scrollBarHeight = horizontalScrollBar.getHeight(); } else { scrollBarHeight = 0; } rectangle.y = bounds.height - rectangle.height - scrollBarHeight; } }
protected JScrollPane createScrollPane( JComponent component, String title, boolean horizontalScrollbar) { JScrollPane scrollPane = new JScrollPane( component, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, horizontalScrollbar ? JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED : JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); Color color = component.getBackground(); if (color == null) { color = Color.white; } scrollPane.setBackground(color); scrollPane.getViewport().setBackground(color); if (title != null) { scrollPane.setBorder(BorderFactory.createTitledBorder(title)); } JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); scrollBar.setPreferredSize(new Dimension(10, scrollBar.getHeight())); if (horizontalScrollbar) { scrollBar = scrollPane.getHorizontalScrollBar(); scrollBar.setPreferredSize(new Dimension(scrollBar.getWidth(), 10)); } return scrollPane; }
public void toChatScreen(String toScreen, boolean selfSeen) throws IOException, BadLocationException { // Timestamp ts = new Timestamp(); String toScreenFinal = ""; Date now = Calendar.getInstance().getTime(); SimpleDateFormat format = new SimpleDateFormat("hh:mm"); String ts = format.format(now); // chatScreen.append(ts + " " + toScreen + "\n"); toScreenFinal = "<font color=gray>" + ts + "</font> "; if (selfSeen) toScreenFinal = toScreenFinal + "<font color=red>" + toScreen + "</font>"; else toScreenFinal = toScreenFinal + toScreen; // chatter.addTo(toScreen); // if(standardWindow) { // chatScreen.setCaretPosition(chatScreen.getDocument().getLength()); // } // else { JScrollBar vBar = scrollChat.getVerticalScrollBar(); int vSize = vBar.getVisibleAmount(); int maxVBar = vBar.getMaximum(); int currVBar = vBar.getValue() + vSize; kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null); if (maxVBar == currVBar) { chatScreen.setCaretPosition(chatScreen.getDocument().getLength()); } // } // kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null); }
public void print(final String line) { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater( new Runnable() { public void run() { ConsoleTab.this.print(line); } }); return; } Document document = this.console.getDocument(); JScrollBar scrollBar = getVerticalScrollBar(); boolean shouldScroll = false; if (getViewport().getView() == this.console) { shouldScroll = scrollBar.getValue() + scrollBar.getSize().getHeight() + MONOSPACED.getSize() * 4 > scrollBar.getMaximum(); } try { document.insertString(document.getLength(), line, null); } catch (BadLocationException localBadLocationException) { } if (shouldScroll) scrollBar.setValue(2147483647); }
/** * Configures the specified component appropriate for the look and feel. This method is invoked * when the ComponentUI instance is being installed as the UI delegate on the specified component. * This method should completely configure the component for the look and feel, including the * following: 1. Install any default property values for color, fonts, borders, icons, opacity, * etc. on the component. Whenever possible, property values initialized by the client program * should not be overridden. 2. Install a LayoutManager on the component if necessary. 3. * Create/add any required sub-components to the component. 4. Create/install event listeners on * the component. 5. Create/install a PropertyChangeListener on the component in order to detect * and respond to component property changes appropriately. 6. Install keyboard UI (mnemonics, * traversal, etc.) on the component. 7. Initialize any appropriate instance data. * * @param c - the component to install the ui on */ public void installUI(JComponent c) { super.installUI(c); JScrollBar hsb = scrollpane.getHorizontalScrollBar(); hsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, Boolean.FALSE); JScrollBar vsb = scrollpane.getVerticalScrollBar(); vsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, Boolean.FALSE); }
private void formComponentResized( java.awt.event.ComponentEvent evt) { // GEN-FIRST:event_formComponentResized if (enBas) { JScrollBar scroll = jScrollPane1.getVerticalScrollBar(); scroll.setValue(scroll.getMaximum() - scroll.getVisibleAmount()); } } // GEN-LAST:event_formComponentResized
public void init() { if (destroyed) { return; } resultPanel = new ResultPanel(); plotPanel.setLayout(new GridLayout(1, 0)); plotButton = new JToggleButton[plotButtonName.length]; for (int i = 0; i < plotButton.length; i++) { plotButton[i] = new JToggleButton(plotButtonName[i]); plotButton[i].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { resultPanel.repaint(); } }); plotPanel.add(plotButton[i]); } plotButton[0].setSelected(true); plotButton[4].setSelected(true); GridBagLayout g = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); mainPanel.setLayout(g); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; c.weighty = 0.0; mainPanel.add(plotPanel, c); yField.setEditable(false); callsField.setEditable(false); JPanel panel = new JPanel(new GridLayout(1, 2)); panel.add(yField); panel.add(callsField); mainPanel.add(panel, c); mainPanel.add(zoomXBar, c); c.gridwidth = 3; c.weightx = 1.0; c.weighty = 1.0; mainPanel.add(resultPanel, c); c.weightx = 0.0; mainPanel.add(zoomYBar, c); mainPanel.add(shiftYBar, c); AdjustmentListener listener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { resultPanel.repaint(); } }; zoomXBar.addAdjustmentListener(listener); zoomYBar.addAdjustmentListener(listener); shiftYBar.addAdjustmentListener(listener); frame.getContentPane().add(mainPanel); frame.setVisible(true); }
/** Returns the coordinates of the top left corner of the value at the given index. */ public Point getCoordinates(int index) { JScrollBar bar = scrollPane.getVerticalScrollBar(); Rectangle r = pinsTable.getCellRect(index, 2, true); pinsTable.scrollRectToVisible(r); return new Point( (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY() - bar.getValue())); }
private static int getScrollAmount(Component c, MouseWheelEvent me, JScrollBar scrollBar) { final int scrollBarWidth = scrollBar.getWidth(); final int ratio = Registry.is("ide.smart.horizontal.scrolling") && scrollBarWidth > 0 ? Math.max((int) Math.pow(c.getWidth() / scrollBarWidth, 2), 10) : 10; // do annoying scrolling faster if smart scrolling is on return me.getUnitsToScroll() * scrollBar.getUnitIncrement() * ratio; }
public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub Dragging = true; startPoint = e.getPoint(); JScrollBar verticalScrollBar = TheScrollPane.getVerticalScrollBar(); JScrollBar horizScrollBar = TheScrollPane.getHorizontalScrollBar(); lastScrollValueX = horizScrollBar.getValue(); lastScrollValueY = verticalScrollBar.getValue(); }
/** * This method is used to append a line of text to be displayed. * * @param text Is the text to be apppended */ private void append(final String text) { this.textArea.append(text); JScrollBar vertBar = this.scrollPane.getVerticalScrollBar(); if (vertBar.getValue() == vertBar.getMaximum() - vertBar.getVisibleAmount()) { this.autoscroll = true; } }
void finishConversion(File outFile, Date start) { isBusy = false; progressBar.setIndeterminate(false); Date end = new Date(); textArea.append( format("Created %s in %s ms.%n", outFile.getPath(), end.getTime() - start.getTime())); JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); scrollBar.setValue(scrollBar.getMaximum()); }
private void refreshInfo() { int channelsCount = mModel.getChannelCount(); mChannelLabel.setVisible(channelsCount > 1); mChannelScrollBar.setVisible(channelsCount > 1); mChannelLabel.setText( String.format("Channel: %s / %s", mModel.getCurrentChannel() + 1, channelsCount)); mChannelScrollBar.setValue(mModel.getCurrentChannel()); mChannelScrollBar.setMaximum(channelsCount); int zPlanesCount = mModel.getZPlanesCount(); mZPlaneLabel.setVisible(zPlanesCount > 1); mZPlaneScrollBar.setVisible(zPlanesCount > 1); mZPlaneLabel.setText( String.format("Z plane: %s / %s", mModel.getCurrentZPlane() + 1, zPlanesCount)); mZPlaneScrollBar.setValue(mModel.getCurrentZPlane()); mZPlaneScrollBar.setMaximum(zPlanesCount); int timePointsCount = mModel.getTimePointCount(); mTimePointScrollBar.setVisible(timePointsCount > 1); mTimePointLabel.setVisible(timePointsCount > 1); mTimePointLabel.setText( String.format("Time point: %s / %s", mModel.getCurrentTimePoint() + 1, timePointsCount)); mTimePointScrollBar.setValue(mModel.getCurrentTimePoint()); mTimePointScrollBar.setMaximum(timePointsCount); }
/** Create a popup menu when mouse click */ private void createPopupMenu(int x, int y) { Action[] popupMenuActions = getPopupMenuActions(); JScrollBar vbar = getTreeTable().getVerticalScrollBar(); myUIFacade.showPopupMenu( this, popupMenuActions, x - getTreeTable().getHorizontalScrollBar().getValue() + (vbar.isVisible() ? vbar.getWidth() : 0), y - vbar.getValue() + getTreeTable().getTable().getTableHeader().getHeight()); }
@Override public void focusGained(FocusEvent fe) { if (-1 == table.getSelectedRow() && table.getRowCount() > 0) { table.setRowSelectionInterval(0, 0); JScrollBar scrollbar = scrollpane.getVerticalScrollBar(); scrollbar.setValue(scrollbar.getMinimum()); } if (-1 == table.getSelectedColumn()) { table.setColumnSelectionInterval(0, 0); } }
public void adjustmentValueChanged(AdjustmentEvent e) { // doe niets als er gedragged wordt if (DEBUG) { System.out.println("adjustmentValueChanged()"); System.out.println("dragging: " + _scroller.getValueIsAdjusting()); } if (!_scroller.getValueIsAdjusting()) scrollViewTo(e.getValue()); }
protected void scrollToCorrectLocation() { JScrollBar verticalScrollBarForScrollPane = _scrollPaneAroundWidgetBox.getVerticalScrollBar(); if ((_selection != null) && (_selection.getParent() != null)) { _selectionRectangle = _selection.getBounds(); _selectionRectangle.y += (_selection.getParent()).getY(); _viewport.scrollRectToVisible(_selectionRectangle); _viewport.repaint(); } else { verticalScrollBarForScrollPane.setValue(0); } return; }
public void scrollToBottom() { if (mousePressed) return; int lengthOfChat = transcriptWindow.getDocument().getLength(); transcriptWindow.setCaretPosition(lengthOfChat); try { JScrollBar scrollBar = textScroller.getVerticalScrollBar(); scrollBar.setValue(scrollBar.getMaximum()); } catch (Exception e) { } }
public void setResultSet(DiskResultSet rset) throws Exception { set = rset; max = rset.getRowCount(); table.setModel(model); table.setModel(this); offset = 0; scrollBar.setValue(0); scrollBar.setMaximum((max < window ? 0 : max - window)); }
public void showMessage(String message) { int x = frame.getX() + (frame.getWidth() - WIDTH) / 2, y = frame.getY() + (frame.getHeight() - HEIGHT) / 2; setLocation(x, y); textArea.append(message + "\n"); int value = jsbar.getMaximum() - jsbar.getVisibleAmount(); jsbar.setValue(value); repaint(); if (!isVisible()) { setVisible(true); } }
private void removeItem(Object obj, Field field, int index) { final JScrollBar sb = genericTagPropertiesEditPanelScrollPanel.getVerticalScrollBar(); final int val = sb.getValue(); // save scroll top SWFType swfType = field.getAnnotation(SWFType.class); if (swfType != null && !swfType .countField() .isEmpty()) { // Fields with same countField must be removed from too Field[] fields = obj.getClass().getDeclaredFields(); for (int f = 0; f < fields.length; f++) { SWFType fieldSwfType = fields[f].getAnnotation(SWFType.class); if (fieldSwfType != null && fieldSwfType.countField().equals(swfType.countField())) { ReflectionTools.removeFromField(obj, fields[f], index); } } try { // If countField exists, decrement, otherwise do nothing Field countField = obj.getClass().getDeclaredField(swfType.countField()); int cnt = countField.getInt(obj); cnt--; countField.setInt(obj, cnt); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { // ignored } } else { ReflectionTools.removeFromField(obj, field, index); } generateEditControls(editedTag, false); // Restore scroll top after some time. TODO: Handle this better. I don't know how :-(. new Thread() { @Override public void run() { try { Thread.sleep(500); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } View.execInEventDispatch( () -> { genericTagPropertiesEditPanelScrollPanel.getVerticalScrollBar().setValue(val); }); } }.start(); revalidate(); repaint(); }
private boolean doHorizontalScrolling(Component c, MouseWheelEvent me) { final JScrollBar scrollBar = findHorizontalScrollBar(c); if (scrollBar != null) { if (scrollBar.hashCode() != myLastHorScrolledComponentHash) { FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.horizontal.scrolling"); myLastHorScrolledComponentHash = scrollBar.hashCode(); } scrollBar.setValue(scrollBar.getValue() + getScrollAmount(c, me, scrollBar)); return true; } return false; }
private void setHotKeys() { InputMap inputMap = mChannelScrollBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), "negativeUnitIncrement"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_E, 0), "positiveUnitIncrement"); inputMap = mZPlaneScrollBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, 0), "negativeUnitIncrement"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0), "positiveUnitIncrement"); inputMap = mTimePointScrollBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, 0), "negativeUnitIncrement"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0), "positiveUnitIncrement"); }
/* * I can't find any property on the scrollBar to determine if it will be * displayed or not so use brute force to determine this. */ protected int getScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane) { int scrollBarWidth = 0; JComboBox comboBox = (JComboBox) popup.getInvoker(); if (comboBox.getItemCount() > comboBox.getMaximumRowCount()) { JScrollBar vertical = scrollPane.getVerticalScrollBar(); scrollBarWidth = vertical.getPreferredSize().width; } return scrollBarWidth; }