1

I am Trying to add a JscrollPane to my JTextPane and it does not show up when i run it. I have searched the internet and most answers do not help at all.

This is how i implemented it in my code

    JTextPane t = new JTextPane();
    JScrollPane s = new JScrollPane(t);
    s.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    t.setBounds(10,50,60,70);
    s.setBounds(10,50,60,70);
    Pane.add(t);
    Pane.add(s);
  • Possible duplicate of [How to have a Scrollable JTextPane?](http://stackoverflow.com/questions/8182473/how-to-have-a-scrollable-jtextpane) – MikeVe Mar 06 '16 at 21:45

1 Answers1

3

Start by getting rid of t.setBounds(10,50,60,70); and s.setBounds(10,50,60,70); and Pane.add(t);. A component can only reside within a single container, by calling Pane.add(t) you are removing the component from it's parent container (the JScrollPane).

Also, make sure you're using appropriate layout managers to manage your layouts (there's no need to call setBounds)

You might also like to have a read through Code Conventions for the Java TM Programming Language, it will make it easier for people to read your code and for you to read others

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366