[英]Jtextarea don't show text
i create in my project a jform on netbeans on Mac , I create him automatically with the drag & drop ,`I put Three button and one jtextarea. 我在我的项目中在Mac上的netbeans上创建了一个jform,然后通过拖放自动创建了他,`我放了三个按钮和一个jtextarea。 In the main of the project I create a new object of the type of this jform. 在项目的主体中,我创建一个与此jform类型的新对象。 the jform appear but the text in the jtextarea don't appear. jform出现,但jtextarea中的文本不出现。
netbeans create automatically initcomponent like this : netbeans自动创建如下的initcomponent:
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("reply");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("reply-all");
jButton3.setText("delete");
jButton4.setText("forward");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4)))
.addContainerGap(23, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(15, Short.MAX_VALUE))
);
pack();
}
i create the constructor like this : 我创建像这样的构造函数:
public MailRead(Email a){
java.awt.EventQueue.invokeLater(() -> {
new MailRead().setVisible(true);
});
Date d=new Date();
this.a=a;
a=new Email("ffd", "edgvxsfz", "h6v4gtrwd","ujyhrstegfw", d,21334231);
initComponents();
//System.out.println("-----Email from : "+a.getMittente()+"-----"+"\n"+"-----Object : "+a.getObj()+"-----\n"+a.getEmail());
String text= "-----Email from : "+a.getMittente()+"-----"+"\n"+"-----Object : "+a.getObj()+"-----\n"+a.getEmail();
jTextArea1=new JTextArea(text);
}
the email code is this : 电子邮件代码是这样的:
import java.io.Serializable;
import java.util.Date;
public class Email implements Serializable{
String mittente;
String destinatario;
String email;
Date dataInvio;
int id;
String obj;
boolean isnew;
public Email(String mittente, String destinatario,String obj, String email, Date dataInvio,int id) {
this.mittente = mittente;
this.destinatario = destinatario;
this.email = email;
this.dataInvio = dataInvio;
this.id=id;
this.obj=obj;
isnew=true;
}
public String getMittente() {
return mittente;
}
public void setMittente(String mittente) {
this.mittente = mittente;
}
public String getDestinatario() {
return destinatario;
}
public void setDestinatario(String destinatario) {
this.destinatario = destinatario;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getObj() {
return obj;
}
public void setObj(String obj) {
this.obj = obj;
}
public Date getDataInvio() {
return dataInvio;
}
public void setDataInvio(Date dataInvio) {
this.dataInvio = dataInvio;
}
public int getId() {
return id;
}
public boolean isIsnew() {
return isnew;
}
public void setIsnew(boolean isnew) {
this.isnew = isnew;
}
@Override
public String toString() {
return "Email{" + "mittente=" + mittente + ", destinatario=" + destinatario + ", email=" + email + ", dataInvio=" + dataInvio + ", id=" + id + '}';
}
} in the contractor I assigned value at the moment in the real code I use the parameters of MailRead how can solve to read the email in jtextarea ? 我现在在实代码中为承包商分配值时,我使用MailRead的参数如何解决在jtextarea中读取电子邮件?
jTextArea1=new JTextArea(text);
Don't create a new JTextArea. 不要创建新的JTextArea。
You want to add text to the existing text area that has been added to the frame. 您想要将文本添加到已添加到框架的现有文本区域中。 So you would use: 因此,您将使用:
jTextArea1.append(text);
This means when you create your MailRead
class you need to pass the text area as a parameter to the MailRead class as well as the Email parameter so your
MailRead` class can append text to the text area. 这意味着,当您创建MailRead
类时,需要将文本区域作为参数传递给MailRead class as well as the Email parameter so your
MailRead`类可以将文本追加到文本区域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.