Add Scroll bar in JEditorPane, setLayout null

152 views Asked by At

I can't add scroll bar on EditorPane.

private JEditorPane editorPane;
private JScrollPane scrollpane;

Container :

Container c = getContentPane();
    c.setLayout(null);
    setBounds(100, 100, 450, 300);

    editorPane = new JEditorPane();
    editorPane.setBounds(0, 54, 434, 208);

    scrollpane = new JScrollPane(editorPane);
    scrollpane.setPreferredSize(new Dimension(350, 110));

    c.add(scrollpane);

.. .. Nothing added

2

There are 2 answers

0
Hovercraft Full Of Eels On BEST ANSWER

You're shooting yourself in the foot here:

editorPane.setBounds(0, 54, 434, 208);

By setting the editorPane's absolute size, you prevent it from expanding when it needs to do so, preventing the JScrollBars from having to show.

Solution: don't do this. And yeah, avoid using null layouts. They'll bite you, as you're finding out. Set the width using CSS

0
Timothy Truckle On
getContentPane().setLayout(null);

This means "I give a damn on the help of others because I know better that anyone else how to layout a GUI!"

So this is where you are.

I'd recomment to go through the tutorials and learn how to build GUIs using LayoutManagers.