2
我有以下問題: 的JTextPane適合墊層JPanel並JFrame的
我就充滿了內容的左側有一個JTextPane
這JTextPane
放入JScrollPane
。此ScrollPane
被添加到JPanel
的BorderLayout.CENTER
,並且這個結果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();
發佈一些SSCCE,演示如何定位組件。 –
@ brano88我做到了;) –
一切工作正常我再次檢查您的代碼,也許你把一些面板上'東'。 –