2

我有以下问题: 在此处输入图像描述

JTextPane在左边有一个充满内容的内容,它JTextPane被放入一个JScrollPane. 这ScrollPane被添加到BorderLayout.CENTERaJPanel并且这个结果JPanel被添加到BorderLayout.CENTER底层JFrame contentPane()

现在我想把它传播到JTextPane整个JFrame/JPanel. 我怎样才能做到这一点?

这是代码:

public class FinishPanelBuilder extends JPanel
{
  /**
   * Serial version UID.
   */
  private static final long serialVersionUID = 4373044358025740572L;
  private Model model;

  /**
   * Constructor to call if you want to build up a new finish panel.
   * 
   * @param model
   */
  public FinishPanelBuilder()
  {
    buildFinishPanel();
  }

  /**
   * Builds up the panel.
   */
  public void buildFinishPanel()
  {
    setLayout(new BorderLayout());

    JTextWrapPane textPaneResult = new JTextWrapPane(); 
    //This is my own class of JTextPane to wrap text
    StyledDocument document = textPaneResult.getStyledDocument();

    textPaneResult.setEditable(false);
    textPaneResult.setBackground(Color.white);
    textPaneResult.setFont(panelLabel.getFont());
    textPaneResult.setAutoscrolls(true);
    textPaneResult.setLineWrap(false);

    JScrollPane scrollPaneTestResult = new JScrollPane(textPaneResult);
    scrollPaneTestResult.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    panelLabel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    setBorder(BorderFactory.createEtchedBorder());
    add(panelLabel, BorderLayout.PAGE_START);
    add(scrollPaneTestResult, BorderLayout.CENTER);
  }
}

这个完整的代码由

JFrame frame = new JFrame(); 
frame.add(new FinishPanelBuilder();
4

1 回答 1

1

好的,我又这样做了,没关系。我不知道为什么。我认为这是一个错误的方法getScrollableTracksViewportWidth()被覆盖的原因。

于 2013-06-13T10:37:15.493 回答