开发者

Java Swing - Problem with inseting component(JTextArea) in JTextPane

开发者 https://www.devze.com 2022-12-20 20:20 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消