第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

GridBagLayout 組件無(wú)法正確顯示

GridBagLayout 組件無(wú)法正確顯示

PIPIONE 2023-07-19 14:54:46
我正在學(xué)習(xí) java swing,這對(duì)我來(lái)說(shuō)很困惑。不顯示退出按鈕。但是,如果我將代碼部分移到textArea按鈕的兩部分之后,它將正確顯示。所以為什么?package exercise1;import javax.swing.*;import java.awt.*;public class ChatClient {    private JTextArea textArea;    private JTextField textField;    private JButton btnSend;    private JButton btnQuit;    private JFrame frame;    private JPanel panel;    private JScrollPane scrollPane;    private void launchFrame() {        panel = new JPanel(new GridBagLayout());        GridBagConstraints c = new GridBagConstraints();        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.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);    }    protected ChatClient() {        frame = new JFrame("Chat Room");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        launchFrame();        frame.add(panel);        frame.pack();        frame.setVisible(true);    }    public static void main(String[] args) {        ChatClient client = new ChatClient();    }}
查看完整描述

1 回答

?
一只名叫tom的貓

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);


}


查看完整回答
反對(duì) 回復(fù) 2023-07-19
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)