Note that there are some explanatory texts on larger screens.

plurals
  1. POJTextArea's append () method doesn't seem to work
    primarykey
    data
    text
    <p>We were assigned to create a simple compiler as a homework that will take set of instructions (containing variables, conditions, jumps, etc.) and evaluate them. That's already done, but I thought I'd make my program little bit more… “shiny”, and add the ability to load instructions from a text file, just for the sake of user comfort; however, it seems that the <code>JTextArea</code>'s <code>append ()</code> method doesn't seem to really like me, as it does exactly nothing. Here's the relevant code:</p> <pre><code>BufferedReader bufferedReader; File file; FileDialog fileDialog = new FileDialog (new Frame (), "Open File", FileDialog.LOAD); String line; fileDialog.setVisible (true); if (fileDialog.getFile () != null) { file = new File (fileDialog.getDirectory () + fileDialog.getFile ()); input.setText (""); // delete old first try { bufferedReader = new BufferedReader (new FileReader (file)); line = bufferedReader.readLine (); while (line != null) { input.append (line); System.out.println (line); line = bufferedReader.readLine (); } } catch (IOException ioe) { ioe.printStackTrace (); } } </code></pre> <p>(I'm using Awt's FileDialog instead of Swing's JFileChooser because it simply looks better on Mac, as seen in <a href="https://developer.apple.com/library/mac/#documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html" rel="nofollow">Apple's official recommendation</a>.)</p> <p>The <code>input</code> variable used in this code points to the JTextArea instance. The funny thing is – the file reading part must be working flawlessly, as I can see the file content being written to the standard output thanks to the <code>System.out.println ()</code> call within the <code>while</code> loop. However, nothing appears in the <code>JTextArea</code>, and I've tried all the existing solutions I've found here on StackOverflow – that includes calling the <code>repaint ()</code>, <code>revalidate ()</code> and <code>updateUI ()</code> methods.</p> <p>What am I missing? Thanks very much for any answer!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload