How to access static jTextField created with swing?

6

So, guys, I have a jTextField that works normally, but when I put it as static setText does not work anymore, and I need it static because I do the same for a function, I did it without swing and it worked out I do not know what's happening right now.

The following is the code below:

//Codigo gerado automaticamento pelo swing

public static javax.swing.JTextField blueBGolem;

blueBGolem.setEditable(false);
blueBGolem.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
blueBGolem.setForeground(new java.awt.Color(255, 255, 255));
blueBGolem.setHorizontalAlignment(javax.swing.JTextField.CENTER);
blueBGolem.setText("5:00");
blueBGolem.setBorder(null);
blueBGolem.setOpaque(false);
Painel.add(blueBGolem);
blueBGolem.setBounds(0, 0, 70, 17);


private void blueBGolemStartActionPerformed(java.awt.event.ActionEvent evt) {                                                
    //timerBlueBGolem.start();
    blueBGolem.setText("ooi");
} 

EDIT

I think it's something in my code but I can not find what ..

follows the complete code

link

    
asked by anonymous 14.03.2014 / 13:44

2 answers

3

The problem is that your variables are not static, just put it as static that solves your problem.

If you are using NetBeans and the "drag components" option configures as below:

If you are manually adding the components you add static to the variables:

public javax.swing.JTextField blueBGolem; // anterior
public static javax.swing.JTextField blueBGolem; // novo
    
18.03.2014 / 15:38
2

You do not need to make your JTextField static. What it mentions about passing a JTextField as an argument to a method can be done without the JTextField being static unless the target method is a static method, such as public static void main (String [] args).

If you are using the JTextField inside the main method, try declaring JTextfield only inside the main method instead of declaring it as a class instance variable.

    
14.03.2014 / 23:24