I have a swing application that creates a number of panels based on a user entered list of names, with a panel for each name that the user enters. At the bottom of the application I have a JPanel, with a button to close the current panel and a JLabel that displays the current number of open panels.
I initialize the label like so
String[] usernames = input("Usernames"); int totalTabs = usernames.length; JLabel lblRemaining = new JLabel("Remaining: " + totalTabs); I have then added an action listener to the close button and have attempted to use a SwingWorker to update the label but it just doesn't seem to update.
close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { unlookup(username); SwingWorker<String, String> updateLabel = new SwingWorker<String, String>(){ @Override protected String doInBackground() throws Exception { String tabTotal = Integer.toString(desktop.getTabCount()); return tabTotal; } @Override protected void done(){ try { lblRemaining.setText(get()); System.out.println(get()); } catch (Exception ignore) { } } }; updateLabel.execute(); } }); The println is showing the correct figure in the console so I know it must be something to do with the GUI not updating but I just can't seem to figure it out!
I'm fairly new to Java and Swing so hopefully it's something fairly obvious that I'm doing wrong!
Thanks :)