JScrollPane中的JEditorPane无法根据需要调整大小 [英] JEditorPane inside JScrollPane not resizing as needed

查看:110
本文介绍了JScrollPane中的JEditorPane无法根据需要调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中实现了注释框功能,用户可以使用鼠标调整其大小.该注释框包含一个滚动窗格,而该滚动窗格包含一个JEditorPane,用户可以在其中插入注释.由于以下原因,我在滚动窗格中添加了编辑器窗格:

I am implementing a Comment box facility in my application which user can resize using mouse. This comment box contains a scrollpane which instead contains a JEditorPane in which user can insert comment. I have added the editor pane inside a scroll pane for the following reason:

自动对jeditorpane进行扫描

当用户调整注释框的大小时,我正在为JScrollPaneJEditorPane设置所需的大小.当用户增加注释框的大小时,这些组件的大小会根据需要增加,但是当注释框的大小减小时,即使设置了大小,JEditorPane的大小也不会减小.这会导致滚动窗格内的滚动条.

When the user resizes the comment box, I am setting the desired size for JScrollPane and the JEditorPane. When the user is increasing the size of the comment box, the size of these components are increasing as desired but when the size of the comment box is decreased, the size of the JEditorPane does not decrease even after setting the size. This leads to the scrollbars inside the scrollpane.

我尝试将setPreferrredSizesetSizesetMaximumSize用于JEditorPane.编辑器窗格的大小仍然没有减小.我尝试在设置大小后调用revalidate()updateUI(),但没有用.

I tried using setPreferrredSize, setSize, setMaximumSize for JEditorPane. Still the size of the editor pane is not reducing. I tried calling revalidate() or updateUI() after the setting of size but no use.

我正在使用Java 1.4.2.

I am using Java 1.4.2.

请为我提供一些见识....

Please provide me some insight....

推荐答案

我知道答案已经很久了,但是对于以后的参考,您需要做的就是覆盖getScrollableTracksViewportWidth()以始终返回true,例如.

I realise this is long since answered, but for future reference all you need to do is override the getScrollableTracksViewportWidth() to always return true, eg.

JEditorPane pane = new JEditorPane() {
    public boolean getScrollableTracksViewportWidth() {
        return true;
    }
};
panel.add(new JScrollPane(pane));

这篇关于JScrollPane中的JEditorPane无法根据需要调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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