Hi Anthony, 2010/1/26 Anthony Petrov <[email protected]>:
> > What concerns me is that file dialogs are modal. And if you invoke its > setVisble(true) on the EDT, the event dispatching is going to be locked. Try > moving the file dialog over the main frame containing some Swing GUI. I > think it's not going to be updated properly, while the XFileDialogPeer > should work OK. Yes, it's true: the EDT is locked when we use the new GtkFileDialogPeer while with the old XFileDialogPeer is OK I wrote a simple program to test it (it's attached): by running it, you can notice like with the GtkFileDialogPeer the JProgressBar is bloked, while with the XFileDialogPeer not. Besides, the button Open & Close has no effect with the GtkFileDialogPeer. I'm reconsidering this subject to find a solution. I've already tried to use a new thread as you suggested, but the in this case the GTKFileDialog doesn't start. Further advices are welcome! Cheers, Costantino
package sun.awt.X11; import java.awt.Dimension; import java.awt.FileDialog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FilenameFilter; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JTextField; import javax.swing.UIManager; /** * Test for FileDialog * * @author Costantino Cerbo ([email protected]) */ public class FileDialogTest { private JFrame frame; private JTextField textField; private FileDialog fileDialog = new FileDialog(frame, "My Gtk File Dialog"); void testFast() { FileDialog fd = new FileDialog((JFrame)null); fd.setVisible(true); System.out.println("Peer: " + fd.getPeer().getClass().getName()); System.out.println("dir: " + fd.getDirectory()); System.out.println("file: " + fd.getFile()); System.out.println("visible: " + fd.isVisible()); fd.dispose(); } void testButton() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); textField = new JTextField(30); fileDialog = new FileDialog(frame, "My Gtk File Dialog"); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.LINE_AXIS)); textField.setMaximumSize(new Dimension(Short.MAX_VALUE, textField.getPreferredSize().height)); mainPanel.add(textField); mainPanel.add(Box.createRigidArea(new Dimension(5,0))); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); mainPanel.add(progressBar); mainPanel.add(Box.createRigidArea(new Dimension(5,0))); JButton openButton = new JButton("Open..."); openButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openFileDialog(FileDialog.LOAD); } }); JButton saveButton = new JButton("Save..."); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openFileDialog(FileDialog.SAVE); } }); JButton openAndCloseButton = new JButton("Open and close..."); openAndCloseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new Thread(new Runnable() { @Override public void run() { System.out.println("start in 3 sec."); try { Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } System.out.println("fileDialog.setVisible(false)"); fileDialog.setVisible(false); } }).start(); System.out.println("openFileDialog..."); openFileDialog(FileDialog.LOAD); } }); mainPanel.add(openButton); mainPanel.add(Box.createRigidArea(new Dimension(5,0))); mainPanel.add(saveButton); mainPanel.add(Box.createRigidArea(new Dimension(5,0))); mainPanel.add(openAndCloseButton); frame.getContentPane().add(mainPanel); frame.pack(); frame.setVisible(true); } FilenameFilter createTextFileFilter() { return new FilenameFilter() { @Override public boolean accept(File dir, String name) { // return name.endsWith(".log"); return name.endsWith(".txt"); } }; } /** * @param frame * @param textField */ private void openFileDialog(int mode) { fileDialog.setMode(mode); if ((new File(textField.getText())).exists()) { fileDialog.setFile(textField.getText()); } //fd.setFilenameFilter(createTextFileFilter()); fileDialog.setVisible(true); System.out.println("Peer: " + fileDialog.getPeer().getClass().getName()); System.out.println("dir: " + fileDialog.getDirectory()); System.out.println("file: " + fileDialog.getFile()); if (fileDialog.getFile() != null) { textField.setText(fileDialog.getDirectory()+fileDialog.getFile()); } } public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); new FileDialogTest().testButton(); //new FileDialogTest().testFast(); } }
