1

垂直分割ペインを含む水平分割ペインがあります。ウィンドウが表示されたら、水平分割ペインの上部にある垂直分割ペインを中央で分割します。横の仕切りを真ん中にしたいです。

私はそれを機能させていますが、ウィンドウが最大化されたときにそのサイズを変更するために水平分割ペインも必要です。(現在はそうではありません。)

また、水平ペインの下にボタンボックスがあり、ウィンドウのサイズが変更されたときに常に表示されるようにしたいと思います。現在、ウィンドウが起動すると、水平分割ですべてを見ることができます。ボタンがウィンドウの推奨サイズ(800、600)に収まらないため、ボタンが表示されません。しかし、私はすべてが自動的にウィンドウに表示され、サイズが変更されたときにウィンドウの境界に接着されたままになりたいです...

これどうやってするの?

ありがとう!

以下は私が現在使用しているコードです。コントローラでcreateメソッドを呼び出します。createViewが最初に呼び出され、次に残りが順番に呼び出されます。


public void createView() {
        dialog = new JFrame();
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog.setVisible(true);
        dialog.setAlwaysOnTop(true);
        dialog.setBounds(0, 0, 800, 600);
        dialog.setMinimumSize(new Dimension(800, 600));
        dialog.setPreferredSize(new Dimension(800, 600));
        dialog.setResizable(true);
        dialog.setTitle("MJLA Class Control Panel");

        contentPanel = new JPanel();
//      contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        contentPanel.setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        dialog.getContentPane().add(contentPanel, BorderLayout.CENTER);

        classQuizSRTSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        contentPanel.add(classQuizSRTSplit, BorderLayout.NORTH);

        classQuizSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        classQuizSRTSplit.setTopComponent(classQuizSplit);




//      classQuizHBox = Box.createHorizontalBox();
//      contentPanel.add(classQuizHBox);

        sRTHBox = Box.createHorizontalBox();
        contentPanel.add(sRTHBox);

        buttonBox = Box.createHorizontalBox();
        contentPanel.add(buttonBox, BorderLayout.SOUTH);

        refreshButton = new JButton("Refresh");
        buttonBox.add(refreshButton);

        doneButton = new JButton("Done");
        buttonBox.add(doneButton);

        this.validateView();
    }

    public void createClassTablePanel() {
        this.classTablePanel = new JPanel();
        this.classTablePanel.setBorder(BorderFactory.createLineBorder(Color.black, 3));
        this.classTablePanel.setPreferredSize(new Dimension(300, 300));
        this.classTablePanel.setLayout(new BorderLayout());

//      this.classQuizHBox.add(classTablePanel);

        this.classQuizSplit.setLeftComponent(classTablePanel);
        classTableModel = cPModel.getClassTableModel();

        classTable = new JTable(this.classTableModel);

        classTable.getSelectionModel().addListSelectionListener(this);
        JScrollPane scrollPane = new JScrollPane(classTable);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        classTablePanel.add(scrollPane, BorderLayout.CENTER);

        this.validateView();
    }

    public void createQuizTablePanel() {
        this.quizTablePanel = new JPanel();
        this.quizTablePanel.setBorder(BorderFactory.createLineBorder(Color.black, 3));
        this.quizTablePanel.setPreferredSize(new Dimension(300, 300));
        this.quizTablePanel.setLayout(new BorderLayout());

//      this.classQuizHBox.add(quizTablePanel);

        this.classQuizSplit.setRightComponent(quizTablePanel);

        quizTableModel = cPModel.getQuizTableModel();
        this.quizSorter = new TableRowSorter<DefaultTableModel>(quizTableModel);

        quizTable = new JTable(this.quizTableModel);
        quizTable.getSelectionModel().addListSelectionListener(this);
        quizTable.setRowSorter(quizSorter);
        JScrollPane scrollPane = new JScrollPane(quizTable);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        quizTablePanel.add(scrollPane, BorderLayout.CENTER);

        Box buttonHBox = Box.createHorizontalBox();
        quizTablePanel.add(buttonHBox, BorderLayout.SOUTH);

        addQuizButton = new JButton("Add Quiz");
        buttonHBox.add(addQuizButton);

        removeQuizButton = new JButton("Remove Quiz");
        buttonHBox.add(removeQuizButton);

        editQuizButton = new JButton("Edit Quiz");
        buttonHBox.add(editQuizButton);

        this.validateView();
    }

    public void createStudentRecordTablePanel() {
        this.studentRecordTablePanel = new JPanel();
        this.studentRecordTablePanel.setBorder(BorderFactory.createLineBorder(Color.black, 3));
        this.studentRecordTablePanel.setLayout(new BorderLayout());

//      this.sRTHBox.add(studentRecordTablePanel);

        this.classQuizSRTSplit.setBottomComponent(studentRecordTablePanel);

        this.studentRecordTableModel = cPModel.getStudentRecordTableModel();
        this.sRTSorter = new TableRowSorter<DefaultTableModel>(studentRecordTableModel);

        sRTTable = new JTable(this.studentRecordTableModel);
        sRTTable.setRowSorter(sRTSorter);
        JScrollPane scrollPane = new JScrollPane(sRTTable);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        studentRecordTablePanel.add(scrollPane, BorderLayout.CENTER);

        Box buttonHBox = Box.createHorizontalBox();
        studentRecordTablePanel.add(buttonHBox, BorderLayout.SOUTH);

        editGradeButton = new JButton("Edit Grade");
        buttonHBox.add(editGradeButton);

        generateReportButton = new JButton("Generate Report");
        buttonHBox.add(generateReportButton);

        this.validateView();
    }

別の問題。

これで、@TrashGodの問題の1つが修正されました。ただし、[完了]ボタンと[更新]ボタンと水平分割ペインの下部との間に大きなギャップがあるのではなく、水平分割ペインのコンポーネントをウィンドウの新しいサイズに合わせてサイズ変更するにはどうすればよいですか?

ウィンドウサイズが変更されたときにイベントをリッスンし、pack()それが発生したときにメソッドを呼び出す必要があると考えていました。それが唯一の方法ですか、それとも機能しますか?(これをテストしただけで、機能しませんでした...すべてを希望のサイズに戻すだけです。


初期の外観。 ここに画像の説明を入力してください


ウィンドウが最大化された後。 ここに画像の説明を入力してください

4

1 に答える 1

4

あなたは見るかもしれませんsetResizeWeight()。の値は0.5、スペースを均等に分散する必要があります。

pack()メソッドは、「サブコンポーネントの優先サイズとレイアウトに合わせてこれをWindowサイズ変更します。」BorderLayout.NORTH仕切りにとどまるのに適したレイアウトのBorderLayout.SOUTHようです。

さらにヘルプが必要な場合は、問題を示すsscceを提供してください。

于 2011-10-19T04:53:40.537 に答える