简体   繁体   English

在Netbeans中设置JLabel文本不起作用

[英]Setting JLabel text in Netbeans not working

I have used the GUI builder to make some JLabel in a JFrame. 我已经使用GUI构建器在JFrame中制作了一些JLabel。 These variables are locked and I find it difficult to use them to in another class. 这些变量被锁定,我发现很难在另一个类中使用它们。

 // Variables declaration - do not modify                     
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
public javax.swing.JLabel title;
// End of variables declaration    

I had to set the variables public before I could use them in a different class. 我必须将变量设置为public,然后才能在其他类中使用它们。

转到init方法并执行

title = new JLabel("This is my Title label. No?");

例如,在initComponent()调用方法之后添加

jLabel2.setText(test text);

You can't set value to the private variables from anotber class. 您不能为anotber类的私有变量设置值。 If you want to do so you can pass the variable as the a parameter and set value. 如果要这样做,可以将变量作为参数传递并设置值。 Or you have to make JLable public. 或者,您必须公开JLable。 ` `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM