how do i add a scrollbar to my JEditorPane

this is the format i have everything in.

private JEditorPane tos;
tos = new JEditorPane();

tos.setEditable(false);
tos.setForeground(new Color(250, 250, 250));
tos.setBackground(new Color(84, 84, 84));
tos.setText("fuuuuuuuuuuuuuuuuuuuuuuuuu bbbarrrrrrrrrrrrrrrrrrrrrrrrr");

addComponent(contentPane, tos, 500,180,210,170);

put that into JScrollPane

f.e.

import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.*;

public class SomeGridLayout extends JPanel {

    private final int VERT_STRUT = 100;
    private final int WEST_GRID_HGAP = 10;
    private final String TEST_BIGTEXT = "<html><body><h2>Path</h2>toto/tutu/tata/TestN<h2>"
            + "Prerequisites</h2>blah blah blah blah<br/><b>blah blah</b> blah blah\nblah blah <u>blah</u> "
            + "blahblah blah blah<h2>Description</h2>blah blah blah blah<br/><b>blah blah</b> blah blah\nblah blah "
            + "<u>blah</u> blahblah blah blah blah\nblah blah blah <br/>lah blah blah <br/>"
            + "lah blah blah blah blah blah blah blah FIN</body></html>";
    private static final long serialVersionUID = 1L;

    public SomeGridLayout() {
        setLayout(new BorderLayout());
        add(Box.createVerticalStrut(VERT_STRUT), BorderLayout.PAGE_START);
        add(Box.createVerticalStrut(VERT_STRUT), BorderLayout.PAGE_END);
        add(createWestPanel(), BorderLayout.LINE_START);
        add(createCenterPanel(), BorderLayout.CENTER);
    }

    private JPanel createCenterPanel() {
        JPanel centerPanel = new JPanel(new GridLayout(2, 2));
        for (int i = 0; i < 4; i++) {
            JEditorPane editorPane = new JEditorPane("text/html", TEST_BIGTEXT);
            JScrollPane scrollpane = new JScrollPane(editorPane);
            centerPanel.add(scrollpane);
        }
        return centerPanel;
    }

    private JPanel createWestPanel() {
        String[] labelStrings = {"AAAAA", "BBBBB"};
        JPanel westPanel = new JPanel(new GridLayout(2, 2, WEST_GRID_HGAP, 0));
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < labelStrings.length; j++) {
                JLabel label = new JLabel(labelStrings[j]);
                JPanel panel = new JPanel();
                panel.add(label);
                westPanel.add(panel);
            }
        }
        return westPanel;
    }

    private static void createAndShowUI() {
        JFrame frame = new JFrame("GridBagLayout");
        frame.getContentPane().add(new SomeGridLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                createAndShowUI();
            }
        });
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.