Example usage for javax.swing ScrollPaneConstants HORIZONTAL_SCROLLBAR_NEVER

List of usage examples for javax.swing ScrollPaneConstants HORIZONTAL_SCROLLBAR_NEVER

Introduction

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

Prototype

int HORIZONTAL_SCROLLBAR_NEVER

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

Click Source Link

Document

Used to set the horizontal scroll bar policy so that horizontal scrollbars are never displayed.

Usage

From source file:utybo.branchingstorytree.swing.editor.StoryNodesEditor.java

public StoryNodesEditor() {
    setLayout(new MigLayout("", "[:33%:300px][grow 150]", "[grow][]"));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    add(scrollPane, "cell 0 0,grow");

    jlist = new JList<>();
    jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jlist.setCellRenderer(new SubstanceDefaultListCellRenderer() {

        @Override//w w w  .j a  v a2s.  c o m
        public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object o,
                int index, boolean isSelected, boolean cellHasFocus) {
            JLabel label = (JLabel) super.getListCellRendererComponent(list, o, index, isSelected,
                    cellHasFocus);

            if (o instanceof StorySingleNodeEditor) {
                if (((StorySingleNodeEditor) o).getStatus() == Status.ERROR)
                    label.setForeground(Color.RED.darker());
                if (o instanceof StoryLogicalNodeEditor)
                    label.setIcon(new ImageIcon(Icons.getImage("LogicalNode", 16)));
                else if (o instanceof StoryTextNodeEditor)
                    label.setIcon(new ImageIcon(Icons.getImage("TextNode", 16)));
                else if (o instanceof StoryVirtualNodeEditor)
                    label.setIcon(new ImageIcon(Icons.getImage("VirtualNode", 16)));
            }

            return label;
        }

    });
    jlist.addListSelectionListener(e -> {
        if (jlist.getSelectedValue() instanceof JComponent) {
            container.removeAll();
            container.add(jlist.getSelectedValue());
            container.revalidate();
            container.repaint();
        }
    });

    JScrollablePanel pan = new JScrollablePanel(new BorderLayout(0, 0));
    jlist.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            scrollPane.revalidate();
            pan.revalidate();
            jlist.revalidate();

            revalidate();
            repaint();
        }

    });
    pan.setScrollableWidth(ScrollableSizeHint.FIT);
    pan.setScrollableHeight(ScrollableSizeHint.STRETCH);
    pan.add(jlist, BorderLayout.CENTER);
    scrollPane.setViewportView(pan);

    container = new JPanel();
    add(container, "cell 1 0,grow");
    container.setLayout(new BorderLayout(0, 0));

    container.add(new JPanel(), BorderLayout.CENTER); // TODO

    JPanel panel = new JPanel();
    add(panel, "cell 0 1 2 1,alignx leading,growy");

    JButton btnAddNode = new JButton(Lang.get("editor.panel.add"),
            new ImageIcon(Icons.getImage("Add Subnode", 16)));
    btnAddNode.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            createMenu().show(btnAddNode, e.getX(), e.getY());
        }
    });
    panel.add(btnAddNode);

    JButton btnRemoveNode = new JButton(Lang.get("editor.panel.remove"),
            new ImageIcon(Icons.getImage("Delete Subnode", 16)));
    btnRemoveNode.addActionListener(e -> removeNode());
    panel.add(btnRemoveNode);

}