[英]JTextPane fit to the underlaying JPanel and JFrame
I have the following problem: 我有以下问题:
I have a JTextPane
on the left filled with content and this JTextPane
is placed into a JScrollPane
. 我有一个
JTextPane
左侧充满了内容,这JTextPane
放入JScrollPane
。 This ScrollPane
is added to the BorderLayout.CENTER
of a JPanel
and this resulting JPanel
is added to BorderLayout.CENTER
of the underlaying JFrame contentPane()
. 将此
ScrollPane
添加到JPanel
的BorderLayout.CENTER
,并将此生成的JPanel
添加到底层JFrame contentPane()
BorderLayout.CENTER
上。
Now I want to spread this JTextPane
all over the JFrame/JPanel
. 现在,我想将此
JTextPane
散布到JFrame/JPanel
。 How can I achieve this? 我该如何实现?
Here is the code: 这是代码:
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);
}
}
This complete code is called by a 完整的代码由
JFrame frame = new JFrame();
frame.add(new FinishPanelBuilder();
Okay, I did this again and it was okay. 好吧,我又做了一次,没关系。 I don't know why.
我不知道为什么 I think it is cause of a wrong method called
getScrollableTracksViewportWidth()
which was overrided. 我认为这是导致错误的方法
getScrollableTracksViewportWidth()
原因,该方法已被覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.