Example usage for javax.swing ScrollPaneConstants HORIZONTAL_SCROLLBAR_AS_NEEDED

List of usage examples for javax.swing ScrollPaneConstants HORIZONTAL_SCROLLBAR_AS_NEEDED

Introduction

In this page you can find the example usage for javax.swing ScrollPaneConstants HORIZONTAL_SCROLLBAR_AS_NEEDED.

Prototype

int HORIZONTAL_SCROLLBAR_AS_NEEDED

To view the source code for javax.swing ScrollPaneConstants HORIZONTAL_SCROLLBAR_AS_NEEDED.

Click Source Link

Document

Used to set the horizontal scroll bar policy so that horizontal scrollbars are displayed only when needed.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();

    JTextPane codearea = new JTextPane();
    JScrollPane scroll;//from   www.  j  a v  a 2  s .  c o m
    scroll = new JScrollPane(codearea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setPreferredSize(new Dimension(300, 300));

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(scroll, BorderLayout.CENTER);
    JButton comp = new JButton("Print text");
    comp.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println(codearea.getText());
        }
    });
    panel.add(comp, BorderLayout.SOUTH);

    frame.getContentPane().add(panel);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.pack();
    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();// ww  w . j  av  a 2 s  .  c om

    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);
}

From source file:Main.java

public Main() {
    super();// w  w  w  .ja v  a2  s.  c  o  m
    this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    Container contentPane = this.getContentPane();
    textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    contentPane.add(pane, BorderLayout.CENTER);
}

From source file:MainClass.java

public MainClass() {
    setLayout(new BorderLayout());

    JPanel jp = new JPanel();
    jp.setLayout(new GridLayout(20, 20));
    int b = 0;//from  w  w  w.  j  a va2  s. com
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 20; j++) {
            jp.add(new JButton("Button " + b));
            ++b;
        }
    }

    // Add panel to a scroll pane.
    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(jp, v, h);

    // Add scroll pane to the content pane.
    add(jsp, BorderLayout.CENTER);

}

From source file:Main.java

private void makeGUI() {

    setLayout(new BorderLayout());

    JPanel jp = new JPanel();
    jp.setLayout(new GridLayout(20, 20));
    int b = 0;/*from   ww w.  ja  va2s. c o  m*/
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 20; j++) {
            jp.add(new JButton("Button " + b));
            ++b;
        }
    }

    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(jp, v, h);

    add(jsp, BorderLayout.CENTER);
}

From source file:net.sf.jabref.gui.help.HelpContent.java

public HelpContent(JabRefPreferences prefs_) {
    super();/*from w ww .  j a v  a 2 s  .c  om*/
    pane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setDoubleBuffered(true);
    prefs = prefs_;
    history = new Stack<>();
    forw = new Stack<>();
    setEditorKitForContentType("text/html", new MyEditorKit());
    setContentType("text/html");
    setText("");
    setEditable(false);

    addHyperlinkListener(new HyperlinkListener() {

        private boolean lastStatusUpdateWasALink = false;

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            String link = e.getDescription();
            if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                // show the link in the status bar - similar to Firefox behavior
                JabRef.jrf.setStatus(link);
                lastStatusUpdateWasALink = true;
            } else {
                if (lastStatusUpdateWasALink) {
                    // remove the link from the status bar
                    JabRef.jrf.setStatus("");
                    lastStatusUpdateWasALink = false;
                }
            }
        }
    });
}

From source file:com.atlassian.theplugin.idea.config.serverconfig.defaultCredentials.TestDefaultCredentialsDialog.java

public TestDefaultCredentialsDialog(Project project, final ProjectConfiguration projectConfiguration,
        final UserCfg defaultCredentials) {
    super(project, false);
    this.project = project;
    addServerTypeServers(new ArrayList<ServerCfg>(projectConfiguration.getAllBambooServers()),
            ServerType.BAMBOO_SERVER, defaultCredentials);

    addServerTypeServers(new ArrayList<ServerCfg>(projectConfiguration.getAllJIRAServers()),
            ServerType.JIRA_SERVER, defaultCredentials);

    setTitle("Testing default credentials");
    setModal(true);/*from  ww w.j  a  va 2s.c om*/

    scroll.getViewport().setOpaque(false);
    scroll.setOpaque(false);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.setBorder(BorderFactory.createEmptyBorder());

    buildServerContent();
    init();
}

From source file:eu.lp0.cursus.ui.AboutDialog.java

private void initialise() {
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(Messages.getString("about.title", Constants.APP_DESC)); //$NON-NLS-1$
    DefaultUnitConverter duc = DefaultUnitConverter.getInstance();

    FormLayout layout = new FormLayout("2dlu, pref, fill:pref:grow, max(30dlu;pref), 2dlu", //$NON-NLS-1$
            "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu, fill:max(100dlu;pref):grow, 2dlu, max(16dlu;pref), 2dlu"); //$NON-NLS-1$
    getContentPane().setLayout(layout);/*w w w.  j  a v  a2s  . c o  m*/

    JLabel lblName = new JLabel(Constants.APP_NAME + ": " + Messages.getString("about.description")); //$NON-NLS-1$ //$NON-NLS-2$
    getContentPane().add(lblName, "2, 2, 3, 1"); //$NON-NLS-1$

    getContentPane().add(new LinkJButton(Constants.APP_URL), "2, 4"); //$NON-NLS-1$

    JScrollPane scrCopying = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    getContentPane().add(scrCopying, "2, 6, 3, 1"); //$NON-NLS-1$

    JTextArea txtCopying = new JTextArea(loadResources("COPYRIGHT", "LICENCE")); //$NON-NLS-1$ //$NON-NLS-2$
    txtCopying.setFont(Font.decode(Font.MONOSPACED));
    txtCopying.setEditable(false);
    scrCopying.setViewportView(txtCopying);
    scrCopying.setPreferredSize(
            new Dimension(scrCopying.getPreferredSize().width, duc.dialogUnitYAsPixel(100, scrCopying)));

    Action actClose = new CloseDialogAction(this);
    JButton btnClose = new JButton(actClose);
    getContentPane().add(btnClose, "4, 8"); //$NON-NLS-1$

    getRootPane().setDefaultButton(btnClose);
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CloseDialogAction.class.getName());
    getRootPane().getActionMap().put(CloseDialogAction.class.getName(), actClose);

    pack();
    setMinimumSize(getSize());
    setSize(getSize().width, getSize().height * 3 / 2);
    btnClose.requestFocusInWindow();
}

From source file:com.filelocker.gui.Events.java

public void make() {
    //      PrintStream oldOut = System.out;

    PrintStream printStream = new PrintStream(new OutputStream() {
        @Override//from   www.  j  a va  2s . c  o  m
        public void write(byte[] buffer, int offset, int length) throws IOException {
            final String text = new String(buffer, offset, length);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    vNotificationArea.append(text);
                }
            });
        }

        @Override
        public void write(int b) throws IOException {
            write(new byte[] { (byte) b }, 0, 1);
        }

    });
    System.setOut(printStream);

    vPasswordField.setEchoChar('#');
    vPasswordLabel.setFont(bigFont);
    vBrowseLabel.setFont(bigFont);
    vNotificationArea.setVisible(false);
    vNotificationArea.setEditable(false);
    vScroller.setVisible(false);
    vScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    vScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    vPanel = new JPanel();
    vPanel.add(vLockButton);
    vPanel.add(vCloseButton);
    vFrame.getContentPane().add(BorderLayout.SOUTH, vPanel);

    vPanel = new JPanel();
    vPanel.add(vPasswordLabel);
    vPanel.add(vPasswordField);
    vPanel.add(vBrowseLabel);
    vPanel.add(vBrowseField);
    vPanel.add(vBrowseButton);
    vPanel.add(vScroller);
    //      vPanel.setLayout (new BoxLayout (vPanel, BoxLayout.Y_AXIS));
    vFrame.getContentPane().add(BorderLayout.CENTER, vPanel);

    vLockButton.addActionListener(new vLockButton_Click());
    vCloseButton.addActionListener(new vCloseButton_Click());

    vBrowseButton.addActionListener(new vBrowseButton_Click());

}

From source file:events.ListSelectionDemo.java

public ListSelectionDemo() {
    super(new BorderLayout());

    String[] listData = { "one", "two", "three", "four", "five", "six", "seven" };
    String[] columnNames = { "French", "Spanish", "Italian" };
    list = new JList(listData);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);//from   w  w w . jav  a 2s  . c om
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    //Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    //Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);

    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    //topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(100, 50));
    topHalf.setPreferredSize(new Dimension(100, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    //XXX: next line needed if bottomHalf is a scroll pane:
    //bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
}