-2

I'll summarize and sorry for my English.

I have a client and a server thread, when touching a button send file is correctly displayed the JFileChooser with showOpenDialog, when want to create a second JFileChooser in the server thread when a file is received, only a blank screen comes out.

I already created the code in a class, in a function, in a new JFrame, and in the same function.

From what I saw, the problem arises when creating the second JFileChooser, since if in the first one I change it by showSaveDialog it shows well.

Code:

class GuardarArchivo extends javax.swing.JFrame {

  JFrame jf = new JFrame();
  jf.setAlwaysOnTop(true);

  JFileChooser elegirRuta = new JFileChooser();

  elegirRuta.setDialogTitle("Selecciona donde guardar el archivo: ");
  int returnVal = elegirRuta.showSaveDialog(jf);

  System.out.print(returnVal);
  ruta = elegirRuta.getSelectedFile().getAbsolutePath();

}

Image:

enter image description here

liquide
  • 1,346
  • 3
  • 20
  • 28
mndv
  • 130
  • 8

1 Answers1

2

Your problem is likely revealed in these comments:

I have a client and a server thread, when touching a button send file is correctly displayed the JFileChooser with showOpenDialog, when want to create a second JFileChooser in the server thread when a file is received, only a blank screen comes out.

You likely have threading issues. You should not be opening a JFileChooser in any thread other than the Swing event dispatch thread (the EDT). Likely the file transfer code is blocking the EDT preventing it from doing its necessary functions, functions that include painting the GUI, hence the all-white dialog. Since you've not posted a valid MCVE I cannot give you an exact solution, other than to recommend that you take care to do all long running code in threads off of the EDT, and all Swing code on the EDT. For more on Swing threading issues please read: Lesson: Concurrency in Swing.

For better help, consider creating and posting a Minimal, Complete, and Verifiable Example Program. We don't want to see your whole program, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem. You might very well solve the problem yourself by simply trying to isolate and expose the bug.

Community
  • 1
  • 1
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373