I am trying to update a jlabel, but the label is not updating. Thanks for any help.

Daniel

package converter;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;

public class modelConverter extends JFrame implements ActionListener,
		ItemListener {
	// Data panel
	// private JTextArea ;
	private JLabel conversionLabel, textArea;
	private JComboBox convData;
	private String outDir, fileOutput = "";
	private String[] fileTypes;
	private File[] sortFiles;
	private ArrayList<File> selectedFiles;
	private File inDir;
	// Control panel
	private JPanel westPanel, eastPanel;
	private JButton input, output, singleFile, convert, clean, exit;
	Runtime r = Runtime.getRuntime();
	Container c = getContentPane();

	// **********************************
	// Constructor
	// **********************************
	public modelConverter() {
		super("3d v.2");

		LookAndFeel lf = UIManager.getLookAndFeel();
		try {
			UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}

		// Create control panel
		westPanel = new JPanel(new GridLayout(5, 2));
		eastPanel = new JPanel();
		conversionLabel = new JLabel("Conversion Type:");

		convData = new JComboBox();
		convData.addItem("IGES -> JT");
		convData.addItem("STP -> JT");
		convData.addItem("WRL -> JT");
		convData.addItemListener(this);

		input = new JButton("Input Directory");
		input.addActionListener(this);
		input.setToolTipText("Select an input directory.");

		output = new JButton("Ouput Directory");
		output.addActionListener(this);
		output.setToolTipText("Select an output directory.");

		singleFile = new JButton("Open a file");
		singleFile.addActionListener(this);
		singleFile.setToolTipText("Open a single file");

		convert = new JButton("Start Conversion");
		convert.setBackground(Color.yellow);
		convert.addActionListener(this);
		convert.setToolTipText("Start converting.");

		clean = new JButton("CGR Clean-up");
		clean.addActionListener(this);
		clean
				.setToolTipText("Clean up cgr conversion. Must define input directory.");

		exit = new JButton("Exit");
		exit.addActionListener(this);
		exit.setToolTipText("Close program.");

		textArea = new JLabel("No files selected");

		// eastPanel.add(textArea);

		westPanel.add(conversionLabel);
		westPanel.add(convData);
		westPanel.add(singleFile);
		westPanel.add(input);
		westPanel.add(output);
		westPanel.add(clean);
		westPanel.add(convert);
		westPanel.add(exit);
		westPanel.add(textArea);

		fileTypes = new String[2];
		fileTypes[0] = "iges";
		fileTypes[1] = "igs";

		c.add(westPanel, BorderLayout.WEST);
		this.setResizable(false);
		setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		pack();
		setVisible(true);
	}// Constructor

	// **********************************
	// actionPerformed - Process the buttons.
	// **********************************

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == output) {
			doOutPut();
		} else if (e.getSource() == input) {
			doInput();
		} else if (e.getSource() == singleFile) {
			getFile();
		} else if (e.getSource() == clean) {
			doCleanUp();
		} else if (e.getSource() == exit) {
			System.exit(0);
		} else {
			doConversion();
		}
	}// actionPerformed

	// **********************************
	// main - Run the convert.
	// **********************************
	public static void main(String args[]) {
		modelConverter ui = new modelConverter();
	}

	// PRIVATE:
	// **********************************
	// doCleanUp - deletes all files that are even
	// interger files with begining name Part_.
	// **********************************
	public void doCleanUp() {
		JFileChooser dirChooser = new JFileChooser(".");
		dirChooser.setMultiSelectionEnabled(true);
		dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int status = dirChooser.showOpenDialog(null);
		File selectedDir[] = dirChooser.getSelectedFiles();
		String dir = "";
		for (int i = 0; i < selectedDir.length; i++) {
			dir = selectedDir[i].toString();
		}
		try {
			String com = "\"H:\\Projects\\Catia Conversion\\Program\\Program\\delete_jt_files.exe\""
					+ " --input_dir=\"" + dir + "\"";
			System.out.println(com);
			String[] cmd = { com };
			Process Z = r.exec(cmd);
		} catch (IOException ioe) {
			System.out.println("the error is " + ioe);
		}
	}

	// **********************************
	// itemStateChanged - define vars for combo box
	// **********************************
	public void itemStateChanged(ItemEvent ie) {
		String s = (String) ie.getItem();
		if (s.equals("IGES -> JT")) {
			fileTypes[0] = "iges";
			fileTypes[1] = "igs";
		} else if (s.equals("WRL -> JT")) {
			fileTypes[0] = "wrl";
			fileTypes[1] = "";
		} else if (s.equals("STP -> JT")) {
			fileTypes[0] = "step";
			fileTypes[1] = "stp";
		}
	}

	// **********************************
	// doInput - define input folder
	// **********************************
	private void doInput() {
		JFileChooser dirChooser = new JFileChooser(".");
		dirChooser.setMultiSelectionEnabled(true);
		dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int status = dirChooser.showOpenDialog(null);
		File selectedDir[] = dirChooser.getSelectedFiles();
		for (int i = 0; i < selectedDir.length; i++) {
			inDir = selectedDir[i];
		}
		getFileType();
	}

	// **********************************
	// doOutput - define output folder.
	// **********************************
	private void doOutPut() {
		JFileChooser dirChooser = new JFileChooser(".");
		dirChooser.setMultiSelectionEnabled(true);
		dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int status = dirChooser.showOpenDialog(null);
		File selectedDir[] = dirChooser.getSelectedFiles();
	}

	// **********************************
	// doInput - define input folder
	// **********************************
	private void getFile() {
		JFileChooser dirChooser = new JFileChooser(".");
		dirChooser.setMultiSelectionEnabled(true);
		dirChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		String display_filter = fileTypes[0];
		if (fileTypes[1] != "") {
			display_filter += ", " + fileTypes[1];
		}
		FileFilter filter1 = new ExtensionFileFilter(display_filter, fileTypes);
		dirChooser.setFileFilter(filter1);
		// dirChooser.addChoosableFileFilter(new inputFilter());
		int status = dirChooser.showOpenDialog(null);
		// File selectedFiles[] =
		File[] arrFiles = dirChooser.getSelectedFiles();
		selectedFiles = new ArrayList<File>();
		for (int z = 0; z < arrFiles.length; z++) {
			selectedFiles.add(arrFiles[z]);
		}
	}

	// **********************************
	// doConversion - start conversion process
	// **********************************
	private void doConversion() {
		Iterator<File> s = selectedFiles.iterator();

		while (s.hasNext()) {
			enabledBtn(false);
			try {
				String exe = "H:\\Projects\\Catia Conversion\\Program\\Program\\"
						+ fileTypes[0] + "tojt.exe";
				String fileInput = s.next().toString();
				String fileName = fileInput.substring(fileInput
						.lastIndexOf("\\"), fileInput.lastIndexOf("."));
				String out = "-o";
				if (outDir == null) {
					int lastIN = fileInput.lastIndexOf(".");
					String newString = fileInput.substring(0, lastIN) + ".jt";
					fileOutput = newString;
				} else {
					fileOutput = outDir;
				}
				textArea.setText(fileName);
				textArea.updateUI();
				textArea.repaint();
				String[] cmd = { exe, fileInput, out, fileOutput };
				Process D = r.exec(cmd);
				try {
					D.waitFor();
				} catch (InterruptedException ex) {
					Logger.getLogger(modelConverter.class.getName()).log(
							Level.SEVERE, null, ex);
				}
				textArea.setText(null);
			} catch (IOException ioe) {
				System.out.println("the error is " + ioe);
			}
		}
		enabledBtn(true);
	}

	// **********************************
	// getFileType - gets file type
	// **********************************

	private void getFileType() {
		sortFiles = inDir.listFiles();
		selectedFiles = new ArrayList<File>();
		for (int z = 0; z < sortFiles.length; z++) {
			String fileName = sortFiles[z].toString().toLowerCase();
			System.out.println(fileName);
			String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
			if (fileExt.equals(fileTypes[0]) || fileExt.equals(fileTypes[1])) {
				selectedFiles.add(sortFiles[z]);
				System.out.println("FOUND: " + sortFiles[z]);
			}
		}
	}

	private void enabledBtn(boolean en) {
		clean.setEnabled(en);
		input.setEnabled(en);
		output.setEnabled(en);
		singleFile.setEnabled(en);
		convert.setEnabled(en);
	}
}

Sorry the updating occurs in the doConversion method.

Got it:

textArea.paintImmediately(textArea.getVisibleRect());

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.