I want to add multiple new JTextArea in 开发者_StackOverflow中文版JTextPane at runtime on button click. For that i have set Box layout for my JTextPane and i add new component in that using mytextpane.add() method. but it is getting resized and repositioned depending on layout and does not retain the original size of it which i had assigned. Also as i add more component to it, the inserted components are getting shrinked but i want a scrollbar to show up when i add more components to my JTextPane. Please help me with this problem.
Generally you add components to a JPanel, so I'm not sure why you are attempting to add them to a JTextPane. The basic code is:
panel.add( someComponent );
panel.revalidate();
However, if you really are trying to add them to a JTextPane then you should be using the insertComponent() method of JTextPane.
If you need more help post your SSCCE showing the problem.
I doubt whether the JTextPane is the component you should be using for this purpose. JTextPane is suited when you want add a multline text editing interface to your UI (say embedding a markup editor). May be JScrollPane would better suit your needs.
精彩评论