Example usage for javax.swing JSlider setOrientation

List of usage examples for javax.swing JSlider setOrientation

Introduction

In this page you can find the example usage for javax.swing JSlider setOrientation.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, enumerationValues = { "JSlider.VERTICAL",
        "JSlider.HORIZONTAL" }, description = "Set the scrollbars orientation to either VERTICAL or HORIZONTAL.")
public void setOrientation(int orientation) 

Source Link

Document

Set the slider's orientation to either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JSlider slider = new JSlider();
    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(true);// www . j a  va 2s .co  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JSlider slider = new JSlider();
    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(false);/*w w  w .j  a  v a2  s.  com*/
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);//from www  . ja va 2 s.com
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(true);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);/*from  www . ja v  a  2s .  com*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(false);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:edu.uci.ics.jung.samples.PerspectiveTransformerDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom and perspective features.
 * /* ww w.  j  a va2  s  . c o m*/
 */
@SuppressWarnings("serial")
public PerspectiveTransformerDemo() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();

    graphLayout = new FRLayout<String, Number>(graph);
    ((FRLayout<String, Number>) graphLayout).setMaxIterations(1000);

    Dimension preferredSize = new Dimension(600, 600);
    Map<String, Point2D> map = new HashMap<String, Point2D>();
    Transformer<String, Point2D> vlf = TransformerUtils.mapTransformer(map);
    grid = this.generateVertexGrid(map, preferredSize, 25);
    gridLayout = new StaticLayout<String, Number>(grid, vlf, preferredSize);

    final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>(
            graphLayout, preferredSize);
    vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);
    PickedState<Number> pes = vv.getPickedEdgeState();
    vv.getRenderContext()
            .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red));
    vv.getRenderContext().setVertexShapeTransformer(new Transformer<String, Shape>() {

        public Shape transform(String v) {
            return new Rectangle2D.Float(-10, -10, 20, 20);
        }
    });
    vv.setBackground(Color.white);

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());

    Container content = getContentPane();
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    content.add(gzsp);

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>();

    vv.setGraphMouse(graphMouse);

    viewSupport = new PerspectiveViewTransformSupport<String, Number>(vv);
    layoutSupport = new PerspectiveLayoutTransformSupport<String, Number>(vv);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 0.9f, vv.getCenter());
        }
    });
    final JSlider horizontalSlider = new JSlider(-120, 120, 0) {

        /* (non-Javadoc)
         * @see javax.swing.JComponent#getPreferredSize()
         */
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(80, super.getPreferredSize().height);
        }
    };

    final JSlider verticalSlider = new JSlider(-120, 120, 0) {

        /* (non-Javadoc)
         * @see javax.swing.JComponent#getPreferredSize()
         */
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(super.getPreferredSize().width, 80);
        }
    };
    verticalSlider.setOrientation(JSlider.VERTICAL);
    final ChangeListener changeListener = new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int vval = -verticalSlider.getValue();
            int hval = horizontalSlider.getValue();

            Dimension d = vv.getSize();
            PerspectiveTransform pt = null;
            pt = PerspectiveTransform.getQuadToQuad(vval, hval, d.width - vval, -hval, d.width + vval,
                    d.height + hval, -vval, d.height - hval,

                    0, 0, d.width, 0, d.width, d.height, 0, d.height);

            viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
            layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
            vv.repaint();
        }
    };
    horizontalSlider.addChangeListener(changeListener);
    verticalSlider.addChangeListener(changeListener);

    JPanel perspectivePanel = new JPanel(new BorderLayout());
    JPanel perspectiveCenterPanel = new JPanel(new BorderLayout());
    perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls"));
    final JButton center = new JButton("Center");
    center.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            horizontalSlider.setValue(0);
            verticalSlider.setValue(0);
        }
    });
    ButtonGroup radio = new ButtonGroup();
    JRadioButton normal = new JRadioButton("None");
    normal.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            boolean selected = e.getStateChange() == ItemEvent.SELECTED;
            if (selected) {
                if (viewSupport != null) {
                    viewSupport.deactivate();
                }
                if (layoutSupport != null) {
                    layoutSupport.deactivate();
                }
            }
            center.setEnabled(!selected);
            horizontalSlider.setEnabled(!selected);
            verticalSlider.setEnabled(!selected);
        }
    });

    final JRadioButton perspectiveView = new JRadioButton("In View");
    perspectiveView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    final JRadioButton perspectiveModel = new JRadioButton("In Layout");
    perspectiveModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            layoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    radio.add(normal);
    radio.add(perspectiveModel);
    radio.add(perspectiveView);
    normal.setSelected(true);

    ButtonGroup graphRadio = new ButtonGroup();
    JRadioButton graphButton = new JRadioButton("Graph");
    graphButton.setSelected(true);
    graphButton.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                visualizationModel.setGraphLayout(graphLayout);
                vv.repaint();
            }
        }
    });
    JRadioButton gridButton = new JRadioButton("Grid");
    gridButton.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                visualizationModel.setGraphLayout(gridLayout);
                vv.repaint();
            }
        }
    });
    graphRadio.add(graphButton);
    graphRadio.add(gridButton);

    JPanel modePanel = new JPanel(new GridLayout(2, 1));
    modePanel.setBorder(BorderFactory.createTitledBorder("Display"));
    modePanel.add(graphButton);
    modePanel.add(gridButton);

    JMenuBar menubar = new JMenuBar();
    menubar.add(graphMouse.getModeMenu());
    gzsp.setCorner(menubar);

    Container controls = new JPanel(new BorderLayout());
    JPanel zoomControls = new JPanel(new GridLayout(2, 1));
    zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel perspectiveControls = new JPanel(new GridLayout(3, 1));
    zoomControls.add(plus);
    zoomControls.add(minus);
    perspectiveControls.add(normal);
    perspectiveControls.add(perspectiveModel);
    perspectiveControls.add(perspectiveView);

    controls.add(zoomControls, BorderLayout.WEST);
    controls.add(modePanel);
    perspectivePanel.add(perspectiveControls, BorderLayout.WEST);
    perspectiveCenterPanel.add(horizontalSlider, BorderLayout.SOUTH);
    perspectivePanel.add(verticalSlider, BorderLayout.EAST);
    perspectiveCenterPanel.add(center);
    perspectivePanel.add(perspectiveCenterPanel);
    controls.add(perspectivePanel, BorderLayout.EAST);

    content.add(controls, BorderLayout.SOUTH);
}

From source file:edu.uci.ics.jung.samples.PerspectiveVertexImageShaperDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./*w  w  w .jav a2s  .  com*/
 * 
 */
@SuppressWarnings("serial")
public PerspectiveVertexImageShaperDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseMultigraph<Number, Number>();
    Number[] vertices = createVertices(11);

    // a Map for the labels
    Map<Number, String> map = new HashMap<Number, String>();
    for (int i = 0; i < vertices.length; i++) {
        map.put(vertices[i], iconNames[i % iconNames.length]);
    }

    // a Map for the Icons
    Map<Number, Icon> iconMap = new HashMap<Number, Icon>();
    for (int i = 0; i < vertices.length; i++) {
        String name = "/images/topic" + iconNames[i] + ".gif";
        try {
            Icon icon = new LayeredIcon(
                    new ImageIcon(PerspectiveVertexImageShaperDemo.class.getResource(name)).getImage());
            iconMap.put(vertices[i], icon);
        } catch (Exception ex) {
            System.err.println("You need slashdoticons.jar in your classpath to see the image " + name);
        }
    }

    createEdges(vertices);

    final VertexStringerImpl<Number> vertexStringerImpl = new VertexStringerImpl<Number>(map);

    final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>(
            new EllipseVertexShapeTransformer<Number>());

    FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph);
    layout.setMaxIterations(100);
    vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400));

    vv.setBackground(Color.decode("0xffffdd"));
    final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>();
    vertexImageShapeFunction.setIconMap(iconMap);
    vertexIconFunction.setIconMap(iconMap);
    vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction);
    vv.getRenderContext().setVertexIconTransformer(vertexIconFunction);
    vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl);
    PickedState<Number> ps = vv.getPickedVertexState();
    ps.addItemListener(new PickWithIconListener(vertexIconFunction));

    vv.addPostRenderPaintable(new VisualizationServer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "Thank You, slashdot.org, for the images!";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 20);
                metrics = g.getFontMetrics(font);
                swidth = metrics.stringWidth(str);
                sheight = metrics.getMaxAscent() + metrics.getMaxDescent();
                x = (d.width - swidth) / 2;
                y = (int) (d.height - sheight * 1.5);
            }
            g.setFont(font);
            Color oldColor = g.getColor();
            g.setColor(Color.lightGray);
            g.drawString(str, x, y);
            g.setColor(oldColor);
        }

        public boolean useTransform() {
            return false;
        }
    });

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Number>());

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>();

    vv.setGraphMouse(graphMouse);

    this.viewSupport = new PerspectiveImageLensSupport<Number, Number>(vv);
    this.layoutSupport = new PerspectiveLayoutTransformSupport<Number, Number>(vv);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 0.9f, vv.getCenter());
        }
    });
    final JSlider horizontalSlider = new JSlider(-120, 120, 0) {

        /* (non-Javadoc)
         * @see javax.swing.JComponent#getPreferredSize()
         */
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(80, super.getPreferredSize().height);
        }
    };

    final JSlider verticalSlider = new JSlider(-120, 120, 0) {

        /* (non-Javadoc)
         * @see javax.swing.JComponent#getPreferredSize()
         */
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(super.getPreferredSize().width, 80);
        }
    };
    verticalSlider.setOrientation(JSlider.VERTICAL);
    final ChangeListener changeListener = new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int vval = -verticalSlider.getValue();
            int hval = horizontalSlider.getValue();

            Dimension d = vv.getSize();
            PerspectiveTransform pt = null;
            pt = PerspectiveTransform.getQuadToQuad(vval, hval, d.width - vval, -hval, d.width + vval,
                    d.height + hval, -vval, d.height - hval,

                    0, 0, d.width, 0, d.width, d.height, 0, d.height);

            viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
            layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
            vv.repaint();
        }
    };
    horizontalSlider.addChangeListener(changeListener);
    verticalSlider.addChangeListener(changeListener);

    JPanel perspectivePanel = new JPanel(new BorderLayout());
    JPanel perspectiveCenterPanel = new JPanel(new BorderLayout());
    perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls"));
    final JButton center = new JButton("Center");
    center.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            horizontalSlider.setValue(0);
            verticalSlider.setValue(0);
        }
    });

    final JCheckBox noText = new JCheckBox("No Text");
    noText.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            JCheckBox cb = (JCheckBox) e.getSource();
            vertexStringerImpl.setEnabled(!cb.isSelected());
            vv.repaint();
        }
    });
    JPanel centerPanel = new JPanel();
    centerPanel.add(noText);

    ButtonGroup radio = new ButtonGroup();
    JRadioButton none = new JRadioButton("None");
    none.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            boolean selected = e.getStateChange() == ItemEvent.SELECTED;
            if (selected) {
                if (viewSupport != null) {
                    viewSupport.deactivate();
                }
                if (layoutSupport != null) {
                    layoutSupport.deactivate();
                }
            }
            center.setEnabled(!selected);
            horizontalSlider.setEnabled(!selected);
            verticalSlider.setEnabled(!selected);
        }
    });
    none.setSelected(true);

    JRadioButton hyperView = new JRadioButton("View");
    hyperView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    JRadioButton hyperModel = new JRadioButton("Layout");
    hyperModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            layoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    radio.add(none);
    radio.add(hyperView);
    radio.add(hyperModel);

    JMenuBar menubar = new JMenuBar();
    JMenu modeMenu = graphMouse.getModeMenu();
    menubar.add(modeMenu);

    panel.setCorner(menubar);

    JPanel scaleGrid = new JPanel(new GridLayout(2, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel controls = new JPanel(new BorderLayout());
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(scaleGrid, BorderLayout.WEST);

    JPanel lensPanel = new JPanel(new GridLayout(2, 0));
    lensPanel.add(none);
    lensPanel.add(hyperView);
    lensPanel.add(hyperModel);

    perspectivePanel.add(lensPanel, BorderLayout.WEST);
    perspectiveCenterPanel.add(horizontalSlider, BorderLayout.SOUTH);
    perspectivePanel.add(verticalSlider, BorderLayout.EAST);
    perspectiveCenterPanel.add(center);
    perspectivePanel.add(perspectiveCenterPanel);
    controls.add(perspectivePanel, BorderLayout.EAST);

    controls.add(centerPanel);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:org.jcurl.demo.tactics.TacticsApp.java

public TacticsApp() {
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            TacticsApp.this.cmdExit();
        }//from ww w.  j a v a  2s .c  o m
    });
    master = new RockEditDisplay();
    master.setPos(mod_locations);
    master.setSpeed(mod_speeds);
    final PositionDisplay pnl2 = new PositionDisplay();
    pnl2.setPos(mod_locations);
    pnl2.setZoom(Zoomer.HOG2HACK);

    final Container con = getContentPane();
    {
        final JPanel p = new JPanel(new BorderLayout());
        p.add(new SumWaitDisplay(mod_locations), "West");
        p.add(master, "Center");
        p.add(new SumShotDisplay(mod_locations), "East");
        con.add(p, "Center");
    }
    // con.add(new SumWaitDisplay(mod_locations), "West");
    con.add(new SumOutDisplay(mod_locations), "West");
    {
        final Box b1 = Box.createHorizontalBox();
        b1.add(Box.createRigidArea(new Dimension(0, 75)));
        b1.add(pnl2);
        con.add(b1, "South");
    }
    final JTabbedPane t = new JTabbedPane();
    con.add(t, "East");
    {
        final Box b0 = Box.createHorizontalBox();
        t.add("Rock", b0);
        {
            final JPanel b1 = new JPanel(new BorderLayout());
            final Box b2 = Box.createVerticalBox();
            b2.add(new JComboBox(new String[] { "Dark", "Light" }));
            b2.add(new JLabel("Broom", SwingConstants.LEFT));
            b1.add(b2, "North");
            JSlider s = new JSlider(-2000, 2000, 0);
            s.setOrientation(SwingConstants.VERTICAL);
            s.setMajorTickSpacing(1000);
            s.setMinorTickSpacing(100);
            s.setPaintLabels(true);
            s.setPaintTicks(true);
            b1.add(s, "Center");

            final Box b3 = Box.createHorizontalBox();
            b3.add(new JFormattedTextField());
            b3.add(new JLabel("mm", SwingConstants.LEFT));
            b1.add(b3, "South");
            b0.add(b1);
        }
        {
            final JPanel b1 = new JPanel(new BorderLayout());
            final Box b2 = Box.createVerticalBox();
            b2.add(new JComboBox(new String[] { "1", "2", "3", "4", "5", "6", "7", "8" }));
            b2.add(new JLabel("Splittime", SwingConstants.LEFT));
            b1.add(b2, "North");
            JSlider s = new JSlider(500, 2500, 1500);
            s.setOrientation(SwingConstants.VERTICAL);
            s.setMajorTickSpacing(1000);
            s.setMinorTickSpacing(100);
            s.setPaintLabels(true);
            s.setPaintTicks(true);
            b1.add(s, "Center");

            final Box b3 = Box.createHorizontalBox();
            b3.add(new JSpinner());
            b3.add(new JLabel("ms", SwingConstants.LEFT));
            b1.add(b3, "South");
            b0.add(b1);
        }
    }
    {
        final Box b0 = Box.createHorizontalBox();
        t.add("Ice", b0);
        {
            final JPanel b1 = new JPanel(new BorderLayout());
            b1.add(new JLabel("Curl"), "North");
            JSlider s = new JSlider(0, 5000, 0);
            s.setOrientation(SwingConstants.VERTICAL);
            s.setMajorTickSpacing(1000);
            s.setMinorTickSpacing(100);
            s.setPaintLabels(true);
            s.setPaintTicks(true);
            b1.add(s, "Center");

            final JSpinner s1 = new JSpinner();
            b1.add(s1, "South");
            b0.add(b1);
        }
        {
            final JPanel b1 = new JPanel(new BorderLayout());
            b1.add(new JLabel("DrawToTee"), "North");
            JSlider s = new JSlider(15000, 30000, 25000);
            s.setOrientation(SwingConstants.VERTICAL);
            s.setMajorTickSpacing(5000);
            s.setMinorTickSpacing(1000);
            s.setPaintLabels(true);
            s.setPaintTicks(true);
            b1.add(s, "Center");

            final JSpinner s1 = new JSpinner();
            b1.add(s1, "South");
            b0.add(b1);
        }
    }
    setJMenuBar(createMenu());
    refreshTitle();
    this.setSize(900, 400);

    new SpeedController(mod_locations, mod_speeds, master);
    new LocationController(mod_locations, pnl2);
    lastSaved = mod_locations.getLastChanged();
}