List of usage examples for javax.swing BoundedRangeModel getExtent
int getExtent();
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);/*from w ww . ja va2s . c o m*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150); frame.setVisible(true); textField.setText("Loooooooooooooooooooooooooooooooooooooooooooooooooooooooong"); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); System.out.println("extent:" + extent); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Offset Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); final JTextField textField = new JTextField(); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); JButton button = new JButton("Get Offset"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Offset: " + textField.getScrollOffset()); System.out.println("Visibility: " + textField.getHorizontalVisibility()); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); }//w w w.j a va 2 s . c om }; button.addActionListener(actionListener); frame.add(button, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:OffsetSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Offset Example"); Container content = frame.getContentPane(); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); final JTextField textField = new JTextField(); label.setLabelFor(textField);//ww w . j a va 2s . c om panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); content.add(panel, BorderLayout.NORTH); JButton button = new JButton("Get Offset"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Offset: " + textField.getScrollOffset()); System.out.println("Visibility: " + textField.getHorizontalVisibility()); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); } }; button.addActionListener(actionListener); content.add(button, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void stateChanged(ChangeEvent event) { try {/*from w ww . j a va2s.c o m*/ Object src = event.getSource(); BoundedRangeModel scrollBarModel = this.chartScrollBar.getModel(); if (src == scrollBarModel) { int val = scrollBarModel.getValue(); int ext = scrollBarModel.getExtent(); Plot plot = this.chartPanel.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot hvp = (XYPlot) plot; ValueAxis axis = hvp.getDomainAxis(); // avoid problems this.chartPanel.getChart().removeChangeListener(this); axis.setRange(val / scrollFactor, (val + ext) / scrollFactor); // restore chart listener this.chartPanel.getChart().addChangeListener(this); } } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
From source file:apidemo.PanScrollZoomDemo.java
/** * Handles a {@link ChangeEvent} (in this case, coming from the scrollbar). * /*from w ww . j av a 2 s .c o m*/ * @param event the event. */ public void stateChanged(final ChangeEvent event) { try { final Object src = event.getSource(); final BoundedRangeModel scrollBarModel = this.scrollBar.getModel(); if (src == scrollBarModel) { final int val = scrollBarModel.getValue(); final int ext = scrollBarModel.getExtent(); final Plot plot = this.chartPanel.getChart().getPlot(); if (plot instanceof XYPlot) { final XYPlot hvp = (XYPlot) plot; final ValueAxis axis = hvp.getDomainAxis(); // avoid problems this.chartPanel.getChart().removeChangeListener(this); axis.setRange(val / this.scrollFactor, (val + ext) / this.scrollFactor); // restore chart listener this.chartPanel.getChart().addChangeListener(this); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java
/** * Overrides Component#setBounds(int, int, int, int) in order to determine * whether an automatic scroll of #chatTextPane to its bottom will be * necessary at a later time in order to keep its vertical scroll bar to its * bottom after the realization of the resize if it is at its bottom before * the resize./*from www . j a v a 2 s . c o m*/ */ @Override public void setBounds(int x, int y, int width, int height) { synchronized (scrollToBottomRunnable) { JScrollBar verticalScrollBar = getVerticalScrollBar(); if (verticalScrollBar != null) { BoundedRangeModel verticalScrollBarModel = verticalScrollBar.getModel(); if ((verticalScrollBarModel.getValue() + verticalScrollBarModel.getExtent() >= verticalScrollBarModel.getMaximum()) || !verticalScrollBar.isVisible()) scrollToBottomIsPending = true; } } super.setBounds(x, y, width, height); }