我正在尝试将 JEditorPane 添加到 JFrame,并且我正在使用 pack() 调整 JFrame 的大小。当我启动程序时,默认大小什么都不做,pack 会生成一个高度约为 10 像素的 JEditorPane。如何使 JEditorPane 以我定义的大小开始?
public class GUIManager extends JFrame {
JButton copyButton = new JButton("Copy");
JButton cutButton = new JButton("Cut");
JButton pasteButton = new JButton("Paste");
JButton selectButton = new JButton("Select All");
JButton clearButton = new JButton("Clear");
JButton searchButton = new JButton("Search");
JButton replaceButton = new JButton("Replace");
JEditorPane editPane;
JScrollPane scrollPane;
JPanel buttons = new JPanel();
public GUIManager(){
buttons.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
editPane = new JEditorPane(){
public boolean getScrollableTrackViewportWidth(){
return true;
}
};
editPane.setSize(500, 500);
scrollPane = new JScrollPane(editPane);
buttons.add(copyButton);
buttons.add(cutButton);
buttons.add(pasteButton);
buttons.add(selectButton);
buttons.add(clearButton);
buttons.add(searchButton);
buttons.add(replaceButton);
this.add(buttons, BorderLayout.NORTH);
this.add(scrollPane, BorderLayout.CENTER);
}
}