[英]Display large String from JTextField in a JLabel
我想將大String
從JTextField
傳輸到JLabel
,但未按預期顯示
例如:
wwwwxxyy ...
當到達JLabel
的結尾時,它停止了,但是我希望它繼續到下一行
請指導我
我的代碼:
String url=txturl.getText();
String uname = txuser.getText();
String pwd = pass.getText();
pass.setVisible(false);
txuser.setVisible(false);
txturl.setVisible(false);
JLabel path=new JLabel();
JLabel username=new JLabel();
JLabel password=new JLabel();
path.setText("path is:"+url.toString());
username.setText("usename is:"+uname);
password.setText("password is:"+pwd);
如果要顯示很多文本,那么JLabel
不是最佳選擇。 由於自動換行功能,合適的替代方法是JTextArea
例如,使用Lorem Ipsum作為要顯示的文本,並將文本區域設置為使用以下textArea.setLineWrap(true);
包裝文本: textArea.setLineWrap(true);
您會看到好處:
(包括textArea.setEditable(false);
如果您不希望用戶修改內容)
有關更多信息,請參見: 如何使用文本區域
還要注意的一點是,從這一行來看: String pwd = pass.getText();
,您不使用JPasswordField
因為不贊成使用getText()
。 如果要考慮的話,請切換到getPassword()
如果沒有,您應該考慮使用JPasswordField
的好處,並在此處閱讀如何使用它們: 如何使用密碼字段
一個關鍵的好處是在鍵入過程中密碼不可見:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.