Java Swing - 在 JTextPane 中插入组件(JTextArea)的问题 [英] Java Swing - Problem with inseting component(JTextArea) in JTextPane

查看:31
本文介绍了Java Swing - 在 JTextPane 中插入组件(JTextArea)的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时单击按钮在 JTextPane 中添加多个新的 JTextArea.为此,我为 JTextPane 设置了 Box 布局,并使用 mytextpane.add() 方法在其中添加了新组件.但它正在根据布局调整大小和重新定位,并且不会保留我分配的原始大小.此外,当我向其中添加更多组件时,插入的组件会缩小,但我希望在向 JTextPane 添加更多组件时显示滚动条.请帮我解决这个问题.

I want to add multiple new JTextArea in 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.

推荐答案

通常您将组件添加到 JPanel,所以我不确定您为什么尝试将它们添加到 JTextPane.基本代码为:

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();

但是,如果您真的想将它们添加到 JTextPane,那么您应该使用 JTextPane 的 insertComponent() 方法.

However, if you really are trying to add them to a JTextPane then you should be using the insertComponent() method of JTextPane.

如果您需要更多帮助,请发布显示问题的 SSCCE.

If you need more help post your SSCCE showing the problem.

这篇关于Java Swing - 在 JTextPane 中插入组件(JTextArea)的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆