1 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
c.gridheight = 1;很簡(jiǎn)單:您在添加 JScrollPane 后忘記重置。如果不這樣做,發(fā)送按鈕將覆蓋退出按鈕。
private void launchFrame() {
panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL; // ** This is also worthwhile **
textArea = new JTextArea(10, 50);
scrollPane = new JScrollPane(textArea);
c.gridx = 0;
c.gridy = 0;
c.gridheight = 3;
panel.add(scrollPane, c);
btnSend = new JButton("Send");
c.gridx = 1;
c.gridy = 0;
c.gridheight = 1; // ********* ADD THIS *********
c.anchor = GridBagConstraints.NORTH;
panel.add(btnSend, c);
btnQuit = new JButton("Quit");
c.gridx = 1;
c.gridy = 1;
c.anchor = GridBagConstraints.NORTH;
panel.add(btnQuit, c);
}
添加回答
舉報(bào)