我有以下问题:
我JTextPane
在左边有一个充满内容的内容,它JTextPane
被放入一个JScrollPane
. 这ScrollPane
被添加到BorderLayout.CENTER
aJPanel
并且这个结果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();