Example usage for javax.swing JScrollBar setValue

List of usage examples for javax.swing JScrollBar setValue

Introduction

In this page you can find the example usage for javax.swing JScrollBar setValue.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The scrollbar's current value.")
public void setValue(int value) 

Source Link

Document

Sets the scrollbar's value.

Usage

From source file:com.diversityarrays.dal.server.ServerGui.java

public ServerGui(Image serverIconImage, IDalServer svr, DalServerFactory factory, File wwwRoot,
        DalServerPreferences prefs) {//from w  w w  . ja  v a2  s .  co  m

    this.serverIconImage = serverIconImage;
    this.dalServerFactory = factory;
    this.wwwRoot = wwwRoot;
    this.preferences = prefs;

    JMenuBar menuBar = new JMenuBar();

    JMenu serverMenu = new JMenu("Server");
    menuBar.add(serverMenu);
    serverMenu.add(serverStartAction);
    serverMenu.add(serverStopAction);
    serverMenu.add(exitAction);

    JMenu commandMenu = new JMenu("Command");
    menuBar.add(commandMenu);
    commandMenu.add(doSql);

    JMenu urlMenu = new JMenu("URL");
    menuBar.add(urlMenu);
    urlMenu.add(new JMenuItem(copyDalUrlAction));
    urlMenu.add(new JMenuItem(showDalUrlQRcodeAction));

    setJMenuBar(menuBar);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    messages.setFont(GuiUtil.createMonospacedFont(12));
    messages.setEditable(false);

    setServer(svr);

    quietOption.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean q = quietOption.isSelected();
            if (server != null) {
                server.setQuiet(q);
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();

    JButton clear = new JButton(new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            messages.setText("");
        }
    });

    final boolean[] follow = new boolean[] { true };
    final JCheckBox followTail = new JCheckBox("Follow", follow[0]);

    followTail.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            follow[0] = followTail.isSelected();
        }
    });

    final OutputStream os = new OutputStream() {
        @Override
        public void write(int b) throws IOException {
            char ch = (char) b;
            messages.append(new Character(ch).toString());
            if (ch == '\n' && follow[0]) {
                verticalScrollBar.setValue(verticalScrollBar.getMaximum());
            }
        }
    };

    TeePrintStream pso = new TeePrintStream(System.out, os);
    TeePrintStream pse = new TeePrintStream(System.err, os);

    System.setErr(pse);
    System.setOut(pso);

    Box box = Box.createHorizontalBox();
    box.add(clear);
    box.add(followTail);
    box.add(quietOption);
    box.add(Box.createHorizontalGlue());

    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(BorderLayout.NORTH, box);
    bottom.add(BorderLayout.SOUTH, statusInfoLine);

    Container cp = getContentPane();
    cp.add(BorderLayout.CENTER, scrollPane);
    cp.add(BorderLayout.SOUTH, bottom);

    pack();
    setSize(640, 480);

    final MemoryUsageMonitor mum = new MemoryUsageMonitor();
    mum.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            statusInfoLine.setMessage(mum.getMemoryUsage());
        }
    });

    if (server == null) {
        // If initial server is null, allow user to specify
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                serverStartAction.actionPerformed(null);
            }
        });
    } else {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                ensureDatabaseInitialisedThenStartServer();
            }
        });
    }
}

From source file:br.com.jinsync.view.FrmJInSync.java

private void rollScroll() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//  w  w w.ja  v  a2s  .  c  o  m
        public void run() {
            JScrollBar temp = scrConsole.getVerticalScrollBar();
            temp.setValue(temp.getMaximum());
        }
    });
}

From source file:ca.uhn.hl7v2.testpanel.ui.editor.Hl7V2MessageEditorPanel.java

private void updateMessageEditor() {

    final JScrollBar vsb = myMessageScrollPane.getVerticalScrollBar();
    int initialVerticalValue = vsb.getValue();

    myMessageEditor.getDocument().removeDocumentListener(myDocumentListener);

    String sourceMessage = myMessage.getSourceMessage();

    if (myMessage.getEncoding() == Hl7V2EncodingTypeEnum.XML) {
        myMessageEditor.setContentType("text/xml");
    } else {/*from   ww w .j  a  va  2  s . co m*/
        myMessageEditor.setContentType("text/er7");
        sourceMessage = sourceMessage.replace('\r', '\n');
    }

    myMessageEditor.setText(sourceMessage);

    myMessageEditor.getDocument().addDocumentListener(myDocumentListener);

    final int verticalValue = Math.min(initialVerticalValue, vsb.getMaximum());

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            // myMessageEditor.setFont(Prefs.getHl7EditorFont());
            vsb.setValue(verticalValue);
        }
    });

}

From source file:lcmc.common.ui.ResourceGraph.java

protected final void initGraph(final Graph<Vertex, Edge> graph) {
    this.graph = graph;

    final Transformer<Vertex, Point2D> vlf = TransformerUtils.mapTransformer(getVertexLocations());
    putVertexLocations();//from www .ja  va  2s .com

    layout = new StaticLayout<Vertex, Edge>(graph, vlf) {
        /* remove the adjust locations part, because scaling is from 0, 0 */
        @Override
        public void setSize(final Dimension size) {
            if (size != null) {
                this.size = size;
                initialize();
            }
        }
    };
    visualizationViewer = new VisualizationViewer<Vertex, Edge>(layout);
    visualizationViewer.setVertexToolTipTransformer(new MyVertexToolTipFunction<Vertex>());
    visualizationViewer.setEdgeToolTipTransformer(new MyEdgeToolTipFunction<Edge>());
    initializeRendering(visualizationViewer);

    /* scaling */
    /* overwriting scaler so that zooming starts from point (0, 0) */
    myScaler = getScalingControl();

    /* picking and popups */
    /* overwriting loadPlugins method only to set scaler */
    final DefaultModalGraphMouse<Vertex, Edge> graphMouse = new DefaultModalGraphMouse<Vertex, Edge>() {
        @Override
        protected void loadPlugins() {
            super.loadPlugins();
            ((ScalingGraphMousePlugin) scalingPlugin).setScaler(myScaler);
            remove(animatedPickingPlugin);
            animatedPickingPlugin = null;
        }
    };
    visualizationViewer.setGraphMouse(graphMouse);
    graphMouse.add(new MyPopupGraphMousePlugin<Vertex, Edge>());
    visualizationViewer.addGraphMouseListener(new MyGraphMouseListener<Vertex>());
    visualizationViewer.setPickSupport(new ShapePickSupport<Vertex, Edge>(visualizationViewer, 50));
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    layout.initialize();
    scrollPane = new GraphZoomScrollPane(visualizationViewer);
    final JScrollBar vScrollBar = scrollPane.getVerticalScrollBar();
    visualizationViewer.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(final MouseWheelEvent e) {
            if ((e.getModifiers() & MouseWheelEvent.CTRL_MASK) > 0) {
                final int amount = e.getWheelRotation();
                vScrollBar.setValue(vScrollBar.getValue() + amount * 20);
                e.consume();
                visualizationViewer.repaint();

            }
        }
    });
}

From source file:lcmc.gui.ResourceGraph.java

/** Inits the graph. */
protected final void initGraph(final Graph<Vertex, Edge> graph) {
    this.graph = graph;

    final Transformer<Vertex, Point2D> vlf = TransformerUtils.mapTransformer(getVertexLocations());
    putVertexLocations();/*from   w w w .  j ava2s  . co m*/

    layout = new StaticLayout<Vertex, Edge>(graph, vlf) {
        /* remove the adjust locations part, because scraling is from 0, 0
        */
        @Override
        public final void setSize(final Dimension size) {
            if (size != null) {
                this.size = size;
                initialize();
            }
        }
    };
    vv = new VisualizationViewer<Vertex, Edge>(layout);
    vv.getRenderContext().setEdgeArrowTransformer(new MyEdgeArrowFunction<Vertex, Edge>());
    vv.getRenderContext().setEdgeLabelClosenessTransformer(
            new ConstantDirectionalEdgeValueTransformer<Vertex, Edge>(0.5, 0.5));
    vv.getRenderContext().setVertexShapeTransformer(new MyVertexShapeSize<Vertex, Edge>(graph, vlf));
    vv.getRenderContext().setVertexFillPaintTransformer(
            new MyPickableVertexPaintFunction<Vertex>(vv.getPickedVertexState(), false));
    vv.getRenderContext().setVertexDrawPaintTransformer(
            new MyPickableVertexPaintFunction<Vertex>(vv.getPickedVertexState(), true));
    vv.getRenderer().setVertexRenderer(pr);

    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());
    vv.setBackground(Tools.getDefaultColor("ResourceGraph.Background"));
    vv.setVertexToolTipTransformer(new MyVertexToolTipFunction<Vertex>());
    vv.setEdgeToolTipTransformer(new MyEdgeToolTipFunction<Edge>());
    vv.getRenderContext().setEdgeShapeTransformer(new MyLine<Vertex, Edge>());
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new MyPickableEdgePaintFunction<Edge>(vv.getPickedEdgeState(), EDGE_DRAW_PAINT, EDGE_PICKED_PAINT));
    vv.getRenderContext().setEdgeFillPaintTransformer(
            new MyPickableEdgePaintFunction<Edge>(vv.getPickedEdgeState(), EDGE_DRAW_PAINT, EDGE_PICKED_PAINT));
    vv.getRenderContext().setArrowDrawPaintTransformer(
            new MyPickableEdgePaintFunction<Edge>(vv.getPickedEdgeState(), EDGE_DRAW_PAINT, EDGE_PICKED_PAINT));
    vv.getRenderContext().setArrowFillPaintTransformer(new MyPickableArrowEdgePaintFunction<Edge>(
            vv.getPickedEdgeState(), EDGE_DRAW_PAINT, EDGE_PICKED_PAINT));

    /* scaling */
    /* overwriting scaler so that zooming starts from point (0, 0) */
    myScaler = getScalingControl();

    /* picking and popups */
    /* overwriting loadPlugins method only to set scaler */
    final DefaultModalGraphMouse<Vertex, Edge> graphMouse = new DefaultModalGraphMouse<Vertex, Edge>() {
        protected void loadPlugins() {
            super.loadPlugins();
            ((ScalingGraphMousePlugin) scalingPlugin).setScaler(myScaler);
            remove(animatedPickingPlugin);
            animatedPickingPlugin = null;
        }
    };
    vv.setGraphMouse(graphMouse);
    graphMouse.add(new MyPopupGraphMousePlugin<Vertex, Edge>());
    vv.addGraphMouseListener(new MyGraphMouseListener<Vertex>());
    vv.setPickSupport(new ShapePickSupport<Vertex, Edge>(vv, 50));
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    layout.initialize();
    scrollPane = new GraphZoomScrollPane(vv);
    final JScrollBar vScrollBar = scrollPane.getVerticalScrollBar();
    vv.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(final MouseWheelEvent e) {
            if ((e.getModifiers() & MouseWheelEvent.CTRL_MASK) > 0) {
                final int amount = e.getWheelRotation();
                vScrollBar.setValue(vScrollBar.getValue() + amount * 20);
                e.consume();
                vv.repaint();

            }
        }
    });
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

public void scrollToBottom() {
    if (prologOutput.isShowing()) {
        prologOutput//from ww w  .  j a v  a2s.  c  o m
                .setCaretPosition(prologOutput.getDocument().getEndPosition().getOffset() - 1 /* OBOB hack */);
        try {
            // If we're in a JScrollPane, force scrolling to bottom and left
            JScrollBar scrollbarV = ((JScrollPane) ((JViewport) (prologOutput.getParent())).getParent())
                    .getVerticalScrollBar();
            scrollbarV.setValue(scrollbarV.getMaximum());
            JScrollBar scrollbarH = ((JScrollPane) ((JViewport) (prologOutput.getParent())).getParent())
                    .getHorizontalScrollBar();
            scrollbarH.setValue(scrollbarH.getMinimum());
        } catch (Exception e) {/* We're not in a JScrollPane, forget it! */

        }
        ;
    }
}

From source file:org.forester.archaeopteryx.ControlPanel.java

void zoomOutY(final float factor) {
    final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
    treepanel.multiplyUrtFactor(0.9f);/*ww  w . j a  v  a2s.c  o  m*/
    if ((treepanel.getYdistance() * factor) > 0.0) {
        final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
        final double x = (sb.getMaximum() - sb.getMinimum()) / (sb.getValue() + (sb.getVisibleAmount() / 2.0));
        treepanel.setYdistance((treepanel.getYdistance() * factor));
        getMainPanel().adjustJScrollPane();
        treepanel.resetPreferredSize();
        getMainPanel().getCurrentScrollPane().getViewport().validate();
        sb.setValue(ForesterUtil
                .roundToInt(((sb.getMaximum() - sb.getMinimum()) / x) - (sb.getVisibleAmount() / 2.0)));
        treepanel.resetPreferredSize();
        treepanel.updateOvSizes();
    }
}

From source file:org.forester.archaeopteryx.ControlPanel.java

void zoomInY(final float factor) {
    final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
    final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
    treepanel.multiplyUrtFactor(1.1f);//www. ja v  a2  s. c o m
    final double x = (sb.getMaximum() - sb.getMinimum()) / (sb.getValue() + (sb.getVisibleAmount() / 2.0));
    treepanel.setYdistance((treepanel.getYdistance() * factor));
    getMainPanel().adjustJScrollPane();
    treepanel.resetPreferredSize();
    getMainPanel().getCurrentScrollPane().getViewport().validate();
    sb.setValue(
            ForesterUtil.roundToInt(((sb.getMaximum() - sb.getMinimum()) / x) - (sb.getVisibleAmount() / 2.0)));
    treepanel.resetPreferredSize();
    treepanel.updateOvSizes();
}

From source file:org.forester.archaeopteryx.ControlPanel.java

void zoomInX(final float factor, final float x_correction_factor) {
    final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
    final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
    treepanel.multiplyUrtFactor(1f);/*  w w  w  .j a  v a  2  s.c  o  m*/
    if ((treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)
            || (treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED)
            || isDrawPhylogram(getMainPanel().getCurrentTabIndex())
            || (getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP)) {
        final double x = (sb.getMaximum() - sb.getMinimum()) / (sb.getValue() + (sb.getVisibleAmount() / 2.0));
        treepanel.setXdistance((treepanel.getXdistance() * factor));
        treepanel.setXcorrectionFactor((treepanel.getXcorrectionFactor() * x_correction_factor));
        getMainPanel().adjustJScrollPane();
        treepanel.resetPreferredSize();
        getMainPanel().getCurrentScrollPane().getViewport().validate();
        sb.setValue(ForesterUtil
                .roundToInt(((sb.getMaximum() - sb.getMinimum()) / x) - (sb.getVisibleAmount() / 2.0)));
    } else {
        final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
        treepanel.setXdistance((treepanel.getXdistance() * factor));
        treepanel.setXcorrectionFactor((treepanel.getXcorrectionFactor() * x_correction_factor));
        getMainPanel().adjustJScrollPane();
        treepanel.resetPreferredSize();
        getMainPanel().getCurrentScrollPane().getViewport().validate();
        sb.setValue(sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount());
    }
    treepanel.resetPreferredSize();
    treepanel.updateOvSizes();
}

From source file:org.forester.archaeopteryx.ControlPanel.java

void zoomOutX(final float factor, final float x_correction_factor) {
    final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
    treepanel.multiplyUrtFactor(1f);/*  w w w .  j a va2s.c  o  m*/
    if ((treepanel.getXdistance() * factor) > 0.0) {
        final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
        if ((treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)
                || (treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED)
                || isDrawPhylogram(getMainPanel().getCurrentTabIndex())
                || (getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP)) {
            getMainPanel().adjustJScrollPane();
            treepanel.resetPreferredSize();
            getMainPanel().getCurrentScrollPane().getViewport().validate();
            final double x = (sb.getMaximum() - sb.getMinimum())
                    / (sb.getValue() + (sb.getVisibleAmount() / 2.0));
            treepanel.setXdistance((treepanel.getXdistance() * factor));
            treepanel.setXcorrectionFactor((treepanel.getXcorrectionFactor() * x_correction_factor));
            getMainPanel().adjustJScrollPane();
            treepanel.resetPreferredSize();
            getMainPanel().getCurrentScrollPane().getViewport().validate();
            sb.setValue(ForesterUtil
                    .roundToInt(((sb.getMaximum() - sb.getMinimum()) / x) - (sb.getVisibleAmount() / 2.0)));
        } else {
            final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
            treepanel.setXdistance(treepanel.getXdistance() * factor);
            treepanel.setXcorrectionFactor(treepanel.getXcorrectionFactor() * x_correction_factor);
            if (x > 0) {
                getMainPanel().adjustJScrollPane();
                treepanel.resetPreferredSize();
                getMainPanel().getCurrentScrollPane().getViewport().validate();
                sb.setValue(sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount());
            }
        }
        treepanel.resetPreferredSize();
        treepanel.updateOvSizes();
    }
}