1

I'm using invokeLater, but it isn't working how I want it to.

I want it to update a jLabel after button click, but it's not outputting to the jLabel.

My program finds the full computer name and then is supposed to update the jLabel within the same instance, but it's not updating at all and I'm unsure why.

I didn't want to paste the whole class in here, but if you want to look at it, here it is: http://pastebin.com/BsU9zST4 Any help is appreciated.

The label is called testLabel

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                MISControlPanel window = new MISControlPanel();
                window.frame.setVisible(true);
                testLabel.setText(CN);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Danielson
  • 2,605
  • 2
  • 28
  • 51
user6680
  • 79
  • 6
  • 34
  • 78
  • Are you getting the value in CN variable .Try to print the variable and see.Are you getting any errors – Madhan Jun 26 '15 at 18:36
  • I'm getting a null value for CN when I put system.out.printlin(CN) – user6680 Jun 26 '15 at 18:39
  • But that code is not executing some class is missing `ComputerQuery.sendParam();`.You forgot to include the ComputerQuery class it seems – Madhan Jun 26 '15 at 18:41
  • ComputerQuery class http://pastebin.com/ARaSaFKN – user6680 Jun 26 '15 at 18:42
  • what's in the 'resultofbatch.txt'.You are reading value from the file and assigning it to CN. where you are writing the value to the file – Madhan Jun 26 '15 at 18:57
  • The result of batch file is outputting "CN=FDCD111304,OU=Workstations,OU=SIM,OU=Accounts,DC=FL,DC=NET" and then the pattern matcher is extracting the computer name out of the txt file. For instance if I search 111255 then the txt file output will says CN=COUL111255, etc... and starting at this block of code is writing it to the file: try (BufferedReader br = new BufferedReader(new FileReader("resultofbatch.txt"))) – user6680 Jun 26 '15 at 19:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/81676/discussion-between-madhan-and-user6680). – Madhan Jun 26 '15 at 19:12
  • The internet I'm using currently is blocking the chat feature. I can use chatbox though if you like? – user6680 Jun 26 '15 at 19:15
  • BufferedReader br = new BufferedReader(new FileReader("resultofbatch.txt") is reading file from txt where is the code to store the values to the file – Madhan Jun 26 '15 at 19:19
  • Do you want to get the Computer Name of the current computer.. I mean local computer – Madhan Jun 26 '15 at 19:24
  • I have it getting the name of the computer based on the partial entry I type. So if I type 111255, the output should be COUL111255. Also BufferedReader br = new BufferedReader(new FileReader("resultofbatch.txt") is writing to the txt file. If I change the txt to resultofbatch2.txt and create a blank txt file in the root directory location, the computer name is written there. – user6680 Jun 26 '15 at 19:33
  • check whether the file resultofbatch.txt is empty or not and check whether the System.out.println(line); inside while loop is printing or not – Madhan Jun 26 '15 at 19:37
  • The resultofbatch.txt isn't empty. When I search for a partial computer name like 111304, the txt file says "CN=FDCD111304,OU=Workstations,OU=SIM,OU=Accounts,DC=FL,DC=NET" so that's working fine. As for the system.out.println(line) nothing outputs. I even changed line to "Hello" but hello didn't output to the console; – user6680 Jun 26 '15 at 19:41
  • then try to put the full path of the file new `FileReader("C:/blah/blah/resultofbatch.txt")` instead of `new FileReader("resultofbatch.txt")` – Madhan Jun 26 '15 at 19:50
  • It's not having an issue with find the folder path otherwise I would get a FileNotFoundException. It's pulling the data because the console says the full computer name, just not in the same instance of the gui. If I relaunch the gui then the computer name I just entered in the previous instance appears in the console. – user6680 Jun 26 '15 at 20:01
  • So you are getting the previous value in label when relaunching the app but not updating the label when the search is done right? – Madhan Jun 26 '15 at 20:08
  • If I comment out testLabel.setText("); in run() method and launch the application to search for computer name and then hit run again, the computer name I just searched for appears in the label. If I close the GUI I just searched for the compuer name and relaunch a new instance, then nothing appears. If I keep testLabel.setText() but set it to setText("Hi"); then the label will always say Hi and never change no matter what instance of the gui I am in. I hope this makes sense. So basically at the moment I have to have the original instance of the gui running in order to get the label to change. – user6680 Jun 26 '15 at 20:18

0 Answers0