在JFrame中调整JEditorPane的大小



我试图将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);
}
}

使用setPreferredSize():

editPane.setPreferredSize(new Dimension(500, 500));

相关内容

  • 没有找到相关文章

最新更新