Note that there are some explanatory texts on larger screens.

plurals
  1. POSWT FileDialog in Applet does not show up
    primarykey
    data
    text
    <p>I am not a SWT user, but I need one of its functionality in JApplet I am working on: FileDialog. And I have problem when I run applet withing a browser: the dialog will not popup, no exception is thrown, nothing (but blink of the window) happens.</p> <p>Applet is only for Windows users, that is the requirement.</p> <p>When I run the same applet from appletviewer in Eclipse, it works fine.</p> <p>I added all the SWT libraries to the PATH in Windows, so they should be available for VM. I searched over the Internet, but I could not find anything that could help me.</p> <p>The code I am using:</p> <pre><code>final Display display = new Display(); final java.awt.Canvas awtParent = new java.awt.Canvas(); applet.getApplet().add(awtParent); final Shell swtParent = SWT_AWT.new_Shell(display, awtParent); try { FileDialog dialog = new FileDialog(swtParent, SWT.OPEN); dialog.setFilterExtensions(getMediaFilesExtensions()); dialog.setFilterNames(new String[] {"All files", "Media Files"}); String fileName = dialog.open(); File[] files = null; if (fileName != null) { files = new File[] { new File(dialog.getFileName()) }; } return files; } finally { display.syncExec(new Runnable () { public void run () { if (swtParent != null &amp;&amp; !swtParent.isDisposed ()) swtParent.dispose (); display.dispose (); applet.getApplet().remove(awtParent); } }); } </code></pre> <p>This code is called while user click on the button. The rest of the application is Swing based.</p> <p>I work on Windows 7 with SWT 3.7.1. All the DLLs are in java.library.path (%PATH% in windows)</p> <p>Do you have any advice?</p> <p>BTW: Swing with native L&amp;F is not an option. I need native file selection dialog.</p> <p>This is the runnable demo applet I created. It requires: swt-win32-x86-3.7.jar.</p> <pre><code>package com.applet; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.io.File; import java.util.Arrays; import javax.swing.*; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.widgets.*; public class DemoApplet extends JApplet { @Override public void init() { JPanel mainPanel = new JPanel(); JButton button = new JButton(new AbstractAction("Select files") { @Override public void actionPerformed(ActionEvent e) { File[] filesNative = getFilesNative(); String msg = "Selected files: " + Arrays.toString(filesNative); JOptionPane.showMessageDialog(null, msg); } }); mainPanel.add(button, BorderLayout.CENTER); add(mainPanel); super.init(); } private File[] getFilesNative() { final Display display = new Display(); final java.awt.Canvas awtParent = new java.awt.Canvas(); add(awtParent); final Shell swtParent = SWT_AWT.new_Shell(display, awtParent); try { FileDialog dialog = new FileDialog(swtParent, SWT.OPEN); dialog.setFilterNames(new String[] {"All files", "Media Files"}); String fileName = dialog.open(); File[] files = null; if (fileName != null) { files = new File[] { new File(dialog.getFileName()) }; } return files; } finally { display.syncExec(new Runnable () { public void run () { if (swtParent != null &amp;&amp; !swtParent.isDisposed ()) swtParent.dispose (); display.dispose (); remove(awtParent); } }); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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