Example usage for javax.swing JScrollPane setVerticalScrollBarPolicy

List of usage examples for javax.swing JScrollPane setVerticalScrollBarPolicy

Introduction

In this page you can find the example usage for javax.swing JScrollPane setVerticalScrollBarPolicy.

Prototype

@BeanProperty(preferred = true, enumerationValues = { "ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED",
        "ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER",
        "ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS" }, description = "The scrollpane vertical scrollbar policy")
public void setVerticalScrollBarPolicy(int policy) 

Source Link

Document

Determines when the vertical scrollbar appears in the scrollpane.

Usage

From source file:Main.java

public static void main(String[] args) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 100; i++) {
        sb.append("this is a test. ");
    }/*from   w w w  . j av  a  2  s  . c o m*/
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextPane newsTextPane = new JTextPane();
    newsTextPane.setContentType("text/html");
    newsTextPane.setEditable(false);
    newsTextPane.setText(sb.toString());

    JScrollPane scrollPane = new JScrollPane(newsTextPane);
    scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    frame.add(scrollPane);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(200, 200);// w ww.ja  v  a 2  s.  c o  m
    f.getContentPane().setLayout(new BorderLayout());
    JTextPane jtp = new JTextPane();
    jtp.setEditorKit(new WrapEditorKit());
    JScrollPane jsp = new JScrollPane(jtp);
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    f.getContentPane().add(jsp, BorderLayout.CENTER);
    jtp.setText("thisIsATestThisisAtestthisIsATestThisisAtestthisIsATestThisisAtest");
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

}

From source file:Main.java

public static void main(String[] args) {
    String subject[] = { "Math", " English", "SQL", "   java", "  c ", " c++ ", " cobol ", "this is a test" };
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList<String> list = new JList<String>(subject);
    JScrollPane s = new JScrollPane(list);
    s.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    s.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    f.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
    f.add(s);//  w  ww  .ja v a  2  s  .  co  m
    f.setSize(300, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    String ITEMS[] = { "Black", "Blue", "Green", "Orange", "Purple", "Red", "White" };
    JList jList = new JList(ITEMS);
    jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scroll = new JScrollPane(jList);
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    JCheckBox chkEnable = new JCheckBox("Enable", true);
    chkEnable.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            jList.setEnabled(chkEnable.isSelected());
        }/*from  ww  w  .  j a  v  a  2s .co  m*/
    });

    JFrame f = new JFrame("Colors");
    Container contentPane = f.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(scroll, BorderLayout.CENTER);
    contentPane.add(chkEnable, BorderLayout.NORTH);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(180, 220);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JTable table = new JTable(22, 5);
    table.setPreferredScrollableViewportSize(new Dimension(400, 300));
    final JScrollPane scrollPane = new JScrollPane(table);
    JButton cornerButton = new JButton("#");
    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER, cornerButton);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    JFrame frame = new JFrame();
    frame.add(scrollPane);// www  .  j a va 2 s .com
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JPanel container = new ScrollablePanel();
    container.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
    for (int i = 0; i < 20; ++i) {
        JPanel p = new JPanel();
        p.setPreferredSize(new Dimension(50, 50));
        p.add(new JLabel("" + i));
        container.add(p);/*from ww w . ja v  a2  s  .c  om*/
    }

    JScrollPane scroll = new JScrollPane(container);
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scroll);
    f.pack();
    f.setSize(250, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label = new JLabel("Label");
    label.setPreferredSize(new Dimension(1000, 1000));
    JScrollPane jScrollPane = new JScrollPane(label);

    JButton jButton1 = new JButton();

    jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jScrollPane.setViewportBorder(new LineBorder(Color.RED));
    jScrollPane.getViewport().add(jButton1, null);

    frame.add(jScrollPane, BorderLayout.CENTER);
    frame.setSize(400, 150);/*  w w  w . j a  v a  2  s.c  o m*/
    frame.setVisible(true);
}

From source file:com.googlecode.sarasvati.visual.jung.JungVisualizer.java

@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
    TestSetup.init();/*from w  w w  .j a  v a 2  s .  c o m*/

    Session session = TestSetup.openSession();
    HibEngine engine = new HibEngine(session);

    JFrame frame = new JFrame("Workflow Visualizer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(800, 600));

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    frame.getContentPane().add(splitPane);

    DefaultListModel listModel = new DefaultListModel();
    for (Graph g : engine.getRepository().getGraphs()) {
        listModel.addElement(g);
    }

    ListCellRenderer cellRenderer = new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

            Graph g = (Graph) value;

            setText(g.getName() + "." + g.getVersion() + "  ");
            return this;
        }
    };

    final JList graphList = new JList(listModel);
    graphList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    graphList.setCellRenderer(cellRenderer);

    JScrollPane listScrollPane = new JScrollPane(graphList);
    listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    splitPane.add(listScrollPane);

    //TreeLayout<NodeRef, Arc> layout = new TreeLayout<NodeRef, Arc>();

    DirectedSparseMultigraph<Node, Arc> graph = new DirectedSparseMultigraph<Node, Arc>();

    //final SpringLayout2<HibNodeRef, HibArc> layout = new SpringLayout2<HibNodeRef, HibArc>(graph);
    //final KKLayout<HibNodeRef, HibArc> layout = new KKLayout<HibNodeRef, HibArc>(graph);
    final TreeLayout layout = new TreeLayout(graph);
    final BasicVisualizationServer<Node, Arc> vs = new BasicVisualizationServer<Node, Arc>(layout);
    //vs.getRenderContext().setVertexLabelTransformer( new NodeLabeller() );
    //vs.getRenderContext().setEdgeLabelTransformer( new ArcLabeller() );
    vs.getRenderContext().setVertexShapeTransformer(new NodeShapeTransformer());
    vs.getRenderContext().setVertexFillPaintTransformer(new NodeColorTransformer());
    vs.getRenderContext().setLabelOffset(5);
    vs.getRenderContext().setVertexIconTransformer(new Transformer<Node, Icon>() {
        @Override
        public Icon transform(Node node) {
            return "task".equals(node.getType()) ? new TaskIcon(node) : null;
        }
    });

    Transformer<Arc, Paint> edgeColorTrans = new Transformer<Arc, Paint>() {
        private Color darkRed = new Color(128, 0, 0);

        @Override
        public Paint transform(Arc arc) {
            return "reject".equals(arc.getName()) ? darkRed : Color.black;
        }
    };

    vs.getRenderContext().setEdgeDrawPaintTransformer(edgeColorTrans);
    vs.getRenderContext().setArrowDrawPaintTransformer(edgeColorTrans);

    final JScrollPane scrollPane = new JScrollPane(vs);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

    splitPane.add(scrollPane);
    scrollPane.setBackground(Color.white);

    graphList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }

            final Graph g = (Graph) graphList.getSelectedValue();

            if ((g == null && currentGraph == null) || (g != null && g.equals(currentGraph))) {
                return;
            }

            currentGraph = g;

            DirectedSparseMultigraph<Node, Arc> jungGraph = new DirectedSparseMultigraph<Node, Arc>();

            for (Node ref : currentGraph.getNodes()) {
                jungGraph.addVertex(ref);
            }

            for (Arc arc : currentGraph.getArcs()) {
                jungGraph.addEdge(arc, arc.getStartNode(), arc.getEndNode());
            }

            GraphTree graphTree = new GraphTree(g);
            layout.setGraph(jungGraph);
            layout.setInitializer(new NodeLocationTransformer(graphTree));
            scrollPane.repaint();
        }
    });

    frame.setVisible(true);
}