1

JEdi​​torPane を 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);
}

}
4

1 に答える 1

2

setPreferredSize()を使用します。

editPane.setPreferredSize(new Dimension(500, 500));
于 2013-03-11T19:14:49.377 に答える