簡體   English   中英

為什么單擊按鈕時無法選擇所有文本?

[英]Why am I unable to select all the text when clicking a button?

我是基於GUI的Java編程的新手,希望對我的查詢有幫助。

import java.awt.*;
import java.awt.event.*;
class Panels
 {
  static Frame f; static TextArea t;
  public static void main(String...xyxxcxcx)
   {
     f=new Frame();
     f.setLayout(new FlowLayout());
     f.setSize(400,300);
     t=new TextArea(); Button b=new Button("Select All");
     f.add(b); f.add(t);
     t.setText("step into the ring with the game");
     b.addActionListener(new ActionListener()
        {
           public void actionPerformed(ActionEvent e)
                {
                    t.selectAll();
                }
            }
                );

    f.setVisible(true);
  }
 }

當我單擊“全選”按鈕時,我希望將選擇文本區域中存在的文本。 但是,這沒有發生。 請指教。

可能正在發生,TextAreabut按鈕具有焦點,因此您永遠看不到它。 如果您選擇了TextArea,則可能會看到所有選定的文本。

如果你打電話怎么辦

public void actionPerformed(ActionEvent e) {
    t.selectAll();
    t.requestFocusInWindow();
}

問題:為什么要使用AWT庫? 已經過時約20年了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM