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

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

在正確的窗口中創(chuàng)建 GUI

在正確的窗口中創(chuàng)建 GUI

aluckdog 2022-07-27 20:32:06
我正在嘗試創(chuàng)建一個(gè)包含 4 個(gè)字段的 GUI。網(wǎng)址用戶名密碼陳述在第一次,這些字段應(yīng)該是空的。稍后,密碼字段旁邊的所有字段都應(yīng)包含上次的信息。問題:GUI 窗口不應(yīng)具有標(biāo)準(zhǔn)大小我想達(dá)到的目標(biāo):當(dāng)窗口打開時(shí),它應(yīng)該動態(tài)調(diào)整到筆記本電腦的屏幕大小,例如中心,屏幕的 20%第四個(gè)字段(語句)可能很長,GUI 窗口會自動變得過長。我想達(dá)到的目標(biāo):對于第四個(gè)字段,應(yīng)將字符串分解為多行。在將字段分解為三行而不是繼續(xù)將其分解為第四行之后,一個(gè)選項(xiàng)可能是滾動條。到目前為止,我已經(jīng)找到了一些可以提供幫助的對象。選項(xiàng)窗格面板第四個(gè)長字段的JTextArea對于JTextArea,還有滾動窗格.setLineWrap(true) 換行.setWrapStyleWord(true)在一個(gè)單詞后換行我的代碼示例:JPanel pane = new JPanel();// adding GridLayoutpane.setLayout(new GridLayout(4,2));// fields are filled just as an example// later they will get substituted by variablesJTextField url = new JTextField ("https:testin.com");JTextField username = new JTextField ("theDude");JTextArea statement = new JTextArea("This statement can becomme very very very long :)");statement.setLineWrap(true);statement.setWrapStyleWord(true);JScrollPane scrollPane = new JScrollPane(statement);pane.add(scrollPane);// add infos to panepane.add(new JLabel ("Enter url: "));pane.add(url);pane.add(new JLabel ("Enter username: "));pane.add(username);pane.add(new JLabel ("Enter password: "));pane.add(new JPasswordField());pane.add(new JLabel ("Enter statement: "));pane.add(statement);//write it to a OK_CANCEL JOptionPaneint option = JOptionPane.showConfirmDialog(null,pane, "Fill all the fields",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
查看完整描述

1 回答

?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊

JTextArea您可以設(shè)置using的高度(可見行數(shù))setRows()。試試下面的例子。我從你的代碼開始,做了一些改動。


import javax.swing.*;

import java.awt.*;


public class ThreeLinesTextArea

{

  public static void main(String[] args)

  {

    JPanel pane = new JPanel();

    // Change to GridBagLayout

    pane.setLayout(new GridBagLayout());

    JTextField url = new JTextField("https:testin.com");

    JTextField username = new JTextField("theDude");


    JTextArea statement = new JTextArea("This statement can becomme very very very long :)");

    statement.setLineWrap(true);

    statement.setWrapStyleWord(true);

    // Use setRows() to make text area have multiple lines

    statement.setRows(3);

    JScrollPane scrollPane = new JScrollPane(statement);


    //This line is removed. scrollPane is added at the end.

    //pane.add(scrollPane);


    pane.add(new JLabel("Enter url: "),

        new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));

    pane.add(url,

        new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));

    pane.add(new JLabel("Enter username: "),

        new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));

    pane.add(username,

        new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));

    pane.add(new JLabel("Enter password: "),

        new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));

    pane.add(new JPasswordField(15),

        new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));

    pane.add(new JLabel("Enter statement: "),

        new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));

    pane.add(scrollPane,

        new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,

            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));


    int option = JOptionPane.showConfirmDialog(null, pane, "Fill all the fields",

        JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

  }

}

輸出:

http://img1.sycdn.imooc.com//62e1308300010dac03410218.jpg

查看完整回答
反對 回復(fù) 2022-07-27
  • 1 回答
  • 0 關(guān)注
  • 116 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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